test(net): make two stop() tests fail when stop() does nothing

AR
11h ago
+36-2

Two tests here fire a stop against a route that never answers and then assert only that the call returned an error:

let result = client.send(&Request::get("/hang"), None, None);
assert!(result.is_err());

The read timeout produces that same error, so both pass with StopHandle::stop() emptied out. I emptied it out to check:

stop_handle_unblocks_a_blocked_read            ok, 7.02s
dead_reader_during_prefill_stops_after_id_wait ok, 5.01s

A test named for an unblocked read that also passes on a timed-out one isn't covering what it's named for. Each now measures how long the call actually took — ~2s when the socket is shut down, ~7s / ~5s when it isn't — so a stop that does nothing fails instead of quietly passing a few seconds later. Thresholds sit between the two bands (4s and 2s), not near either, and the read timeout stays at 30s.

The route sleeps drop from 30s to 2s. They only need to hold the read open past the 200ms stop / 100ms id_wait; everything after that is teardown. ServerHandle::stop() joins every connection thread before returning (bind_and_run), so a handler parked for the full read timeout makes teardown wait out a deadline the assertion already met.

One thing worth flagging separately, since it is a design question and not mine to change here: a test can only reach the teardown path if it stops the client itself, so the 30s sleeps were never the bound being measured. As long as ServerHandle::stop() joins the handler, any long handler makes shutdown wait.

Verification

  • cargo test --lib: 630 passed, 31.8s → 6.8s, stable across 12 consecutive runs
  • cargo fmt --check clean, cargo clippy --all-targets -- -D warnings clean
  • Both tests verified to fail when stop() is emptied: 7.02s > 4s, 5.00s > 2s

Note on building this branch: plain main does not link on macOS here — -nostdinc++ and its SDK operand reach cc as an input file. That is what #245 fixes; I applied it locally to run the gate and did not include it here, so this PR stays test-only.


Summary by cubic

Makes two stop() tests fail when StopHandle::stop() does nothing, so a broken stop no longer passes on the read timeout.

Both tests fired a stop against a route that never answers and asserted only that the call returned an error, but the 30s read timeout produces that same error. Each test now measures call duration, with a threshold set between the shutdown band (~2s) and the timeout band (~5–7s), so a void stop() fails the test instead of passing a few seconds later. The /hang and /chat handler sleeps drop from 30s to 2s — they only need to outlast the 200ms stop and 100ms id_wait, and ServerHandle::stop() joins every connection thread, so longer sleeps made teardown wait out a deadline the assertion already met.

Verification

  • cargo test --lib: 630 passed, suite time drops 31.8s → 6.8s, stable across 12 runs.
  • cargo fmt --check and cargo clippy --all-targets -- -D warnings both clean.
  • Both tests verified to fail when stop() is emptied: 7.02s > 4s and 5.00s > 2s.

Summary by CodeRabbit

  • Tests
    • Added timing checks for network requests that are stopped while waiting for a response or during prefill. These checks verify that cancellation returns promptly rather than waiting for the full read timeout, helping detect regressions in request shutdown behavior. Test server delays are shorter, keeping these checks more efficient while still validating the expected response to a stop request.