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.
This commit is contained in:
Codex committed 2026-10-19 11:38:08 -07:00
1 parent 3a896a5efc
commit 094bb727d3
1 file changed
+6 -2
+6 -2
View File
@@ -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}");
}