H: keep the token listener open for the whole loop
The 500 ms accept window covered only the first case; a connection made later went unseen. Accept once after the loop instead.
This commit is contained in:
1 parent
a78303c123
commit
5f9f160666
1 file changed
+5
-11
+5
-11
@@ -658,16 +658,6 @@ mod tests {
|
||||
async fn a_refused_token_file_sends_nothing() {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let port = listener.local_addr().unwrap().port();
|
||||
let asked = Arc::new(std::sync::atomic::AtomicBool::new(false));
|
||||
let seen = Arc::clone(&asked);
|
||||
tokio::spawn(async move {
|
||||
if tokio::time::timeout(Duration::from_millis(500), listener.accept())
|
||||
.await
|
||||
.is_ok()
|
||||
{
|
||||
seen.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||
}
|
||||
});
|
||||
let transport = ReqwestTransport::new(&limits(4, 8, 1024)).unwrap();
|
||||
for (body, mode) in [
|
||||
("ok-token\r\nsmuggled: 1\n", 0o600),
|
||||
@@ -691,8 +681,12 @@ mod tests {
|
||||
assert!(!format!("{err:?}").contains("ok-token"));
|
||||
let _ = std::fs::remove_file(&token);
|
||||
}
|
||||
// The listener stayed open for every case, so any attempt to reach the
|
||||
// peer is still queued here rather than lost in a timing window.
|
||||
assert!(
|
||||
!asked.load(std::sync::atomic::Ordering::SeqCst),
|
||||
tokio::time::timeout(Duration::from_millis(250), listener.accept())
|
||||
.await
|
||||
.is_err(),
|
||||
"a peer was contacted without a usable token"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user