From 3318ced6febd484363a3a42fbb85ce9da3687925 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Thu, 15 Aug 2024 08:56:12 -0700 Subject: [PATCH] tests: handle ECONNREFUSED in uds_stream::epollhup ## 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... This commit was cherry-picked from PR #6769. --- 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(()) }