Skip to content

Commit 7d6028e

Browse files
committed
smite: Also check for Self::Target in is_timeout
1 parent b3d6ba3 commit 7d6028e

1 file changed

Lines changed: 30 additions & 4 deletions

File tree

smite/src/scenarios.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ impl ScenarioError {
3535
#[must_use]
3636
pub fn is_timeout(&self) -> bool {
3737
use std::io::ErrorKind;
38-
if let Self::Connection(ConnectionError::Io(e)) = self {
39-
matches!(e.kind(), ErrorKind::TimedOut | ErrorKind::WouldBlock)
40-
} else {
41-
false
38+
match self {
39+
Self::Connection(ConnectionError::Io(e)) | Self::Target(TargetError::Io(e)) => {
40+
matches!(e.kind(), ErrorKind::TimedOut | ErrorKind::WouldBlock)
41+
}
42+
_ => false,
4243
}
4344
}
4445
}
@@ -142,3 +143,28 @@ pub fn smite_run<S: Scenario>() -> std::process::ExitCode {
142143

143144
ExitCode::SUCCESS
144145
}
146+
147+
#[cfg(test)]
148+
mod tests {
149+
use super::ScenarioError;
150+
use crate::{noise::ConnectionError, scenarios::TargetError};
151+
use std::io::{Error, ErrorKind};
152+
153+
fn assert_is_timeout(kind: ErrorKind, expected: bool) {
154+
let actual =
155+
ScenarioError::Connection(ConnectionError::Io(Error::new(kind, "test"))).is_timeout();
156+
assert_eq!(actual, expected, "ConnectionError::Io with kind {kind:?}");
157+
let actual = ScenarioError::Target(TargetError::Io(Error::new(kind, "test"))).is_timeout();
158+
assert_eq!(actual, expected, "TargetError::Io with kind {kind:?}");
159+
}
160+
161+
#[test]
162+
fn is_timeout() {
163+
for kind in [ErrorKind::TimedOut, ErrorKind::WouldBlock] {
164+
assert_is_timeout(kind, true);
165+
}
166+
// everything else should return false, but it's hard to test
167+
// "everything else", so we just test one other kind
168+
assert_is_timeout(ErrorKind::ConnectionRefused, false);
169+
}
170+
}

0 commit comments

Comments
 (0)