test(shutdown): wait for the handler to start instead of 100 ms
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 7m54s

in_flight_request_finishes_after_shutdown_fires failed twice on CI (#350,
#352) with hyper's IncompleteMessage. It fired shutdown a fixed 100 ms
after sending the request. On a busy runner the connection could be
accepted before its request was read; graceful shutdown rightly closes
such an idle connection, and the test failed although no in-flight
request was dropped.

The handler now signals when it has started, and shutdown fires only
then, so the test checks what its name says: a request being handled
finishes during the drain.

Verified: 40 runs, four at a time, all pass.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-09-23 17:35:50 +02:00
1 parent ff62bf4210
commit 264a789049
1 file changed
+16 -8
+16 -8
View File
@@ -148,16 +148,19 @@ mod tests {
#[tokio::test]
async fn in_flight_request_finishes_after_shutdown_fires() {
// Arrange: a handler that blocks until the test releases it.
// Arrange: a handler that says when it has started, then blocks until
// the test releases it.
let (started_tx, started_rx) = oneshot::channel::<()>();
let (release_tx, release_rx) = oneshot::channel::<()>();
let release_rx = std::sync::Arc::new(tokio::sync::Mutex::new(Some(release_rx)));
let handles = std::sync::Arc::new(tokio::sync::Mutex::new(Some((started_tx, release_rx))));
let router = axum::Router::new().route(
"/slow",
get(move || {
let release_rx = release_rx.clone();
let handles = handles.clone();
async move {
if let Some(rx) = release_rx.lock().await.take() {
let _ = rx.await;
if let Some((started, release)) = handles.lock().await.take() {
let _ = started.send(());
let _ = release.await;
}
"done"
}
@@ -167,10 +170,15 @@ mod tests {
let (trigger, shutdown) = channel();
let server = tokio::spawn(serve(listener, router, shutdown, Duration::from_secs(5)));
// Act: start the request, fire shutdown while it is in flight, then
// let the handler finish.
// Act: start the request and fire shutdown once the handler is running.
// Waiting a fixed time instead raced a slow runner: a connection
// accepted but not yet read is idle, and graceful shutdown rightly
// closes it, which failed the test without any request being dropped.
let request = tokio::spawn(reqwest::get(format!("http://{addr}/slow")));
tokio::time::sleep(Duration::from_millis(100)).await;
tokio::time::timeout(Duration::from_secs(5), started_rx)
.await
.expect("the request reaches the handler")
.expect("handler started");
trigger.fire();
tokio::time::sleep(Duration::from_millis(100)).await;
let _ = release_tx.send(());