mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-19 08:26:19 +00:00
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:
1 parent
3a896a5efc
commit
094bb727d3
1 file changed
+6
-2
@@ -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}");
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user