From 728292f53c7aa176d99884d6693213921c3d858c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Wed, 25 Nov 2026 13:17:15 +0500 Subject: [PATCH] Test: make the model-list mock server reliable on Windows The accepted socket inherits the listener's non-blocking mode, so the first read could fail and reset the client. Send the response in one write and let the client close first. Co-Authored-By: Claude Sonnet 5.5 --- crates/coa-core/src/modules/pbc/models.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/coa-core/src/modules/pbc/models.rs b/crates/coa-core/src/modules/pbc/models.rs index baf9e32..42bee6a 100644 --- a/crates/coa-core/src/modules/pbc/models.rs +++ b/crates/coa-core/src/modules/pbc/models.rs @@ -192,6 +192,8 @@ mod tests { Err(error) => panic!("Mock model endpoint did not receive its request: {error}"), } }; + // Windows hands the listener's non-blocking mode to the accepted socket. + socket.set_nonblocking(false).unwrap(); socket.set_read_timeout(Some(Duration::from_secs(3))).unwrap(); let mut request = String::new(); let mut reader = BufReader::new(&socket); @@ -202,7 +204,11 @@ mod tests { } request.push_str(&line.to_ascii_lowercase()); } - write!(socket, "HTTP/1.1 {status}\r\nContent-Length: {}\r\nConnection: close\r\n{headers}\r\n{body}", body.len()).unwrap(); + let response = format!("HTTP/1.1 {status}\r\nContent-Length: {}\r\nConnection: close\r\n{headers}\r\n{body}", body.len()); + socket.write_all(response.as_bytes()).unwrap(); + // Closing too early resets the connection on Windows: end our side, then wait for the client. + socket.shutdown(std::net::Shutdown::Write).ok(); + std::io::copy(&mut socket, &mut std::io::sink()).ok(); request }).collect() });