67c03b2
commit 67c03b2
1 file changed
+4 -2
Showing 1 changed file+4-2
▼crates/justapi-core/src/resilience.rs
+4-2
| @@ -1218,13 +1218,15 @@ mod tests { | ||
1218 | 1218 | |
1219 | 1219 | #[tokio::test] |
1220 | 1220 | async fn test_timeout_zero_duration() { |
1221 | + // Use 1ns instead of 0ms to avoid undefined behavior with tokio's timeout. | |
1222 | + // A 0ms timeout may let the handler complete before being cancelled. | |
1221 | 1223 | let slow_handler: HandlerFn<TestBody> = Arc::new(|_req: Request<TestBody>| { |
1222 | 1224 | Box::pin(async { |
1223 | - tokio::time::sleep(Duration::from_millis(5)).await; | |
1225 | + tokio::time::sleep(Duration::from_millis(50)).await; | |
1224 | 1226 | Ok(json_response(StatusCode::OK, "ok")) |
1225 | 1227 | }) |
1226 | 1228 | }); |
1227 | - let mw = TimeoutMiddleware::new(Duration::from_millis(0)); | |
1229 | + let mw = TimeoutMiddleware::new(Duration::from_nanos(1)); | |
1228 | 1230 | let mut chain = crate::middleware::MiddlewareChain::new(slow_handler); |
1229 | 1231 | chain.add(mw); |
1230 | 1232 | let resp = chain.run(test_req(hyper::Method::GET, "/")).await.unwrap(); |
1231 | 1233 | |