From 56f3f40c1567b906279f0d6f8a34c146616708cf Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Fri, 16 Aug 2024 01:55:32 -0700 Subject: [PATCH] tests: handle ECONNREFUSED in `uds_stream::epollhup` (#6778) ## Motivation Currently, the test `uds_stream::epollhup` expects that a `UdsStream::connect` future to a Unix socket which is closed by the accept side to always fail with `io::ErrorKind::ConnectionReset`. On illumos, and potentially other systems, it instead fails with `io::ErrorKind::ConnectionRefused`. This was discovered whilst adding an illumos CI job in PR #6769. See: https://github.com/tokio-rs/tokio/pull/6769#issuecomment-2284753794 ## Solution This commit changes the test to accept either `ConenctionReset` or `ConnectionRefused`. This way, we are more tolerant of different operating systems which may decide to return slightly different errnos here. Both ECONNREFUSED and ECONNRESET seem reasonable to expect in this situation, although arguably, ECONNREFUSED is actually more correct: the acceptor did not accept the connection at all, which seems like "refusing" it to me... --- tokio/tests/uds_stream.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tokio/tests/uds_stream.rs b/tokio/tests/uds_stream.rs index b8c4e6a8eed..cb40cbd1832 100644 --- a/tokio/tests/uds_stream.rs +++ b/tokio/tests/uds_stream.rs @@ -406,6 +406,17 @@ async fn epollhup() -> io::Result<()> { drop(listener); let err = connect.await.unwrap_err(); - assert_eq!(err.kind(), io::ErrorKind::ConnectionReset); + let errno = err.kind(); + assert!( + // As far as I can tell, whether we see ECONNREFUSED or ECONNRESET here + // seems relatively inconsistent, at least on non-Linux operating + // systems. The difference in meaning between these errnos is not + // particularly well-defined, so let's just accept either. + matches!( + errno, + io::ErrorKind::ConnectionRefused | io::ErrorKind::ConnectionReset + ), + "unexpected error kind: {errno:?} (expected ConnectionRefused or ConnectionReset)" + ); Ok(()) }