Skip to content

Commit

Permalink
tests: handle ECONNREFUSED in uds_stream::epollhup (#6778)
Browse files Browse the repository at this point in the history
## 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:
#6769 (comment)

## 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...
  • Loading branch information
hawkw committed Aug 16, 2024
1 parent 2d697fc commit 56f3f40
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tokio/tests/uds_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

0 comments on commit 56f3f40

Please sign in to comment.