Skip to content

Commit dfac298

Browse files
committed
test(gateway): cover with_list_timeout (ok / err / timeout paths)
Adds unit tests for the feature-discovery list-call timeout helper introduced in this PR: a completing future yields Some(Ok), an erroring future yields Some(Err), and a never-resolving future yields None (timeout). The timeout case runs under tokio's paused clock so it resolves instantly instead of waiting the full 10s LIST_TIMEOUT. Signed-off-by: Mohammod Al Amin Ashik <maa.ashik00@gmail.com>
1 parent 715c003 commit dfac298

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

crates/mcpmux-gateway/src/pool/features/discovery.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,36 @@ impl FeatureDiscoveryService {
163163
.await
164164
}
165165
}
166+
167+
#[cfg(test)]
168+
mod tests {
169+
use super::*;
170+
use std::future::pending;
171+
172+
#[tokio::test]
173+
async fn with_list_timeout_returns_some_ok_when_future_completes() {
174+
let out =
175+
FeatureDiscoveryService::with_list_timeout("tools/list", async { Ok::<i32, &str>(42) })
176+
.await;
177+
assert!(matches!(out, Some(Ok(42))));
178+
}
179+
180+
#[tokio::test]
181+
async fn with_list_timeout_propagates_inner_error() {
182+
let out = FeatureDiscoveryService::with_list_timeout("prompts/list", async {
183+
Err::<i32, &str>("boom")
184+
})
185+
.await;
186+
assert!(matches!(out, Some(Err("boom"))));
187+
}
188+
189+
#[tokio::test(start_paused = true)]
190+
async fn with_list_timeout_returns_none_on_timeout() {
191+
// A future that never resolves. Under tokio's paused clock the runtime
192+
// auto-advances to the LIST_TIMEOUT deadline, so this resolves to a
193+
// timeout without actually waiting 10 seconds.
194+
let never = pending::<Result<i32, &str>>();
195+
let out = FeatureDiscoveryService::with_list_timeout("resources/list", never).await;
196+
assert!(out.is_none());
197+
}
198+
}

0 commit comments

Comments
 (0)