From 094bb727d3b4ee7e8c7408d3816db13efe78ca06 Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 19 Oct 2026 11:38:08 -0700 Subject: [PATCH] Print: the no-listener test takes a port the OS says is free, not port 1 The last case of error_statuses_and_broken_replies_are_errors called printers(&Endpoint::Tcp("127.0.0.1", 1)) and expected Error::Unreachable. No port is guaranteed closed: on a FreeBSD CI VM something accepted on port 1 and reset the connection, so the client got as far as sending and the test failed with "print server reply: sending: Broken pipe (os error 32)" instead. Bind 127.0.0.1:0, read its port and drop the listener, so the case uses a port the OS has just released, and keep the assertion. The fake() helper in the same file already takes its port that way. A held port really does read differently, which is why the old case asserted a property of the machine rather than of the client: against a listener that accepts and closes immediately, printers() returns "print server reply: reading: An existing connection was forcibly closed by the remote host. (os error 10054)" on Windows, not Error::Unreachable. cargo test -p photocraft-ipp: 9 passed / 0 failed, the changed test five runs in a row; clippy --all-targets -- -D warnings and cargo fmt --check clean. --- crates/ipp/src/tests.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/ipp/src/tests.rs b/crates/ipp/src/tests.rs index ff3ccb6a49..0737236c69 100644 --- a/crates/ipp/src/tests.rs +++ b/crates/ipp/src/tests.rs @@ -186,8 +186,12 @@ fn error_statuses_and_broken_replies_are_errors() { assert!(matches!(printers(&ep), Err(Error::Protocol(_)))); let (ep, _rx) = fake(b"not ipp at all".to_vec(), false, 200); assert!(matches!(printers(&ep), Err(Error::Protocol(_)))); - // Nobody listening. - let e = printers(&Endpoint::Tcp("127.0.0.1".into(), 1)).unwrap_err(); + // Nobody listening. No port is guaranteed free - on a CI VM something can hold port 1 and reset the + // connection - so take one the OS says is free and release it again. + let free = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); + let port = free.local_addr().unwrap().port(); + drop(free); + let e = printers(&Endpoint::Tcp("127.0.0.1".into(), port)).unwrap_err(); assert!(matches!(e, Error::Unreachable(_)), "{e}"); }