QuickDID is a high-performance AT Protocol identity resolution service written in Rust. It provides handle-to-DID resolution with Redis-backed caching and queue processing.
···11111212// Internal modules - crate visibility only
1313pub(crate) mod handle_resolution_result; // Internal serialization format
1414+1515+// Test helpers
1616+#[cfg(test)]
1717+mod test_helpers;
···176176 }
177177}
178178179179-/// Generic work type for different kinds of background tasks
180180-#[derive(Debug, Clone, Serialize, Deserialize)]
181181-pub(crate) enum WorkItem {
182182- /// Handle resolution work
183183- HandleResolution(HandleResolutionWork),
184184- // Future work types can be added here
185185-}
186186-187179/// Redis-backed queue adapter implementation.
188180///
189181/// This adapter uses Redis lists with a reliable queue pattern:
···554546555547 #[tokio::test]
556548 async fn test_redis_queue_adapter_push_pull() {
557557- // This test requires Redis to be running
558558- let redis_url = match std::env::var("TEST_REDIS_URL") {
559559- Ok(url) => url,
560560- Err(_) => {
561561- eprintln!("Skipping test: Set TEST_REDIS_URL to run Redis tests");
562562- return;
563563- }
564564- };
565565-566566- // Import create_redis_pool
567567- use crate::cache::create_redis_pool;
568568-569569- let pool = match create_redis_pool(&redis_url) {
570570- Ok(p) => p,
571571- Err(e) => {
572572- eprintln!("Failed to create Redis pool: {}", e);
573573- return;
574574- }
549549+ let pool = match crate::test_helpers::get_test_redis_pool() {
550550+ Some(p) => p,
551551+ None => return,
575552 };
576553577554 // Create adapter with unique prefix for testing
···603580604581 #[tokio::test]
605582 async fn test_redis_queue_adapter_reliable_queue() {
606606- let redis_url = match std::env::var("TEST_REDIS_URL") {
607607- Ok(url) => url,
608608- Err(_) => {
609609- eprintln!("Skipping test: Set TEST_REDIS_URL to run Redis tests");
610610- return;
611611- }
612612- };
613613-614614- use crate::cache::create_redis_pool;
615615-616616- let pool = match create_redis_pool(&redis_url) {
617617- Ok(p) => p,
618618- Err(e) => {
619619- eprintln!("Failed to create Redis pool: {}", e);
620620- return;
621621- }
583583+ let pool = match crate::test_helpers::get_test_redis_pool() {
584584+ Some(p) => p,
585585+ None => return,
622586 };
623587624588 let test_prefix = format!("test:queue:{}:", uuid::Uuid::new_v4());
···658622659623 #[tokio::test]
660624 async fn test_redis_queue_adapter_depth() {
661661- let redis_url = match std::env::var("TEST_REDIS_URL") {
662662- Ok(url) => url,
663663- Err(_) => {
664664- eprintln!("Skipping test: Set TEST_REDIS_URL to run Redis tests");
665665- return;
666666- }
667667- };
668668-669669- use crate::cache::create_redis_pool;
670670-671671- let pool = match create_redis_pool(&redis_url) {
672672- Ok(p) => p,
673673- Err(e) => {
674674- eprintln!("Failed to create Redis pool: {}", e);
675675- return;
676676- }
625625+ let pool = match crate::test_helpers::get_test_redis_pool() {
626626+ Some(p) => p,
627627+ None => return,
677628 };
678629679630 let test_prefix = format!("test:queue:{}:", uuid::Uuid::new_v4());
···705656706657 #[tokio::test]
707658 async fn test_redis_queue_adapter_health() {
708708- let redis_url = match std::env::var("TEST_REDIS_URL") {
709709- Ok(url) => url,
710710- Err(_) => {
711711- eprintln!("Skipping test: Set TEST_REDIS_URL to run Redis tests");
712712- return;
713713- }
714714- };
715715-716716- use crate::cache::create_redis_pool;
717717-718718- let pool = match create_redis_pool(&redis_url) {
719719- Ok(p) => p,
720720- Err(e) => {
721721- eprintln!("Failed to create Redis pool: {}", e);
722722- return;
723723- }
659659+ let pool = match crate::test_helpers::get_test_redis_pool() {
660660+ Some(p) => p,
661661+ None => return,
724662 };
725663726664 let adapter = Arc::new(RedisQueueAdapter::<String>::with_config(
+36
src/test_helpers.rs
···11+//! Test helper utilities for QuickDID tests
22+#![cfg(test)]
33+44+use crate::cache::create_redis_pool;
55+use deadpool_redis::Pool;
66+77+/// Helper function to get a Redis pool for testing.
88+///
99+/// Returns None if TEST_REDIS_URL is not set, logging a skip message.
1010+/// This consolidates the repeated Redis test setup code.
1111+pub(crate) fn get_test_redis_pool() -> Option<Pool> {
1212+ match std::env::var("TEST_REDIS_URL") {
1313+ Ok(url) => match create_redis_pool(&url) {
1414+ Ok(pool) => Some(pool),
1515+ Err(e) => {
1616+ eprintln!("Failed to create Redis pool: {}", e);
1717+ None
1818+ }
1919+ },
2020+ Err(_) => {
2121+ eprintln!("Skipping test: Set TEST_REDIS_URL to run Redis tests");
2222+ None
2323+ }
2424+ }
2525+}
2626+2727+/// Macro to skip Redis tests if pool is not available
2828+#[macro_export]
2929+macro_rules! require_redis {
3030+ () => {
3131+ match $crate::test_helpers::get_test_redis_pool() {
3232+ Some(pool) => pool,
3333+ None => return,
3434+ }
3535+ };
3636+}