Repository navigation
test(net): make two stop() tests fail when stop() does nothing #252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2067,9 +2067,18 @@ mod tests { | |
| // A server route that never answers; stop_handle().stop() must | ||
| // unblock the client's read instead of hanging until the read | ||
| // timeout. | ||
| // | ||
| // The handler sleep only keeps the read blocked; what has to hold is | ||
| // that `send()` returns *before* the read timeout. Asserting | ||
| // `result.is_err()` alone does not say that: the read timeout produces | ||
| // the same `Err`, so a `stop()` that does nothing still passes it once | ||
| // the read runs out. The elapsed check below is what separates an | ||
| // unblocked read from a timed-out one -- measured here, a void `stop()` | ||
| // takes ~7s to reach the same `Err`, against ~2s when the socket is | ||
| // actually shut down. | ||
| let mut server = Server::new(); | ||
| server.route("GET", "/hang", |_req, _res, _peer| { | ||
| std::thread::sleep(Duration::from_secs(30)); | ||
| std::thread::sleep(Duration::from_secs(2)); | ||
| }); | ||
| let (mut handle, port) = server.bind_and_run("127.0.0.1").unwrap(); | ||
|
|
||
|
|
@@ -2084,8 +2093,15 @@ mod tests { | |
| thread::sleep(Duration::from_millis(200)); | ||
| stop.stop(); | ||
| }); | ||
| let started = Instant::now(); | ||
| let result = client.send(&Request::get("/hang"), None, None); | ||
| let elapsed = started.elapsed(); | ||
| assert!(result.is_err()); | ||
| assert!( | ||
| elapsed < Duration::from_secs(4), | ||
| "stop() must unblock the read, not let it run to the 30s read \ | ||
| timeout; send() returned after {elapsed:?}" | ||
| ); | ||
|
Comment on lines
+2100
to
+2104
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Make the stopper wait until the socket is stored before calling
Have the stopper poll
|
||
| stopper.join().unwrap(); | ||
| handle.stop(); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: This elapsed assertion can flake because the stopper may run before
send()populatesClient::active;stop()then does nothing and the read exceeds the threshold. Establish the connection before spawning the stopper, or synchronize the stopper with the active connection.Prompt for AI agents