Skip to content

Commit

Permalink
Fix old tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
finnbear committed Jan 14, 2025
1 parent ac35062 commit 9604f25
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ impl Error {

/// Returns true if the error was caused by a timeout.
pub fn is_timeout(&self) -> bool {
#[cfg(all(feature = "http1", feature = "server"))]
if matches!(self.inner.kind, Kind::HeaderTimeout) {
return true;
}
self.find_source::<TimedOut>().is_some()
}

Expand Down
8 changes: 4 additions & 4 deletions tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1504,14 +1504,14 @@ async fn header_read_timeout_slow_writes() {
tcp.write_all(
b"\
Something: 1\r\n\
\r\n\
",
)
.expect("write 2");
thread::sleep(Duration::from_secs(6));
tcp.write_all(
b"\
Works: 0\r\n\
\r\n\
",
)
.expect_err("write 3");
Expand Down Expand Up @@ -1553,7 +1553,7 @@ async fn header_read_timeout_starts_immediately() {
.timer(TokioTimer)
.header_read_timeout(Duration::from_secs(2))
.serve_connection(socket, unreachable_service());
conn.await.expect_err("header timeout");
assert!(conn.await.unwrap_err().is_timeout());
}

#[tokio::test]
Expand Down Expand Up @@ -1601,14 +1601,14 @@ async fn header_read_timeout_slow_writes_multiple_requests() {
b"\
GET / HTTP/1.1\r\n\
Something: 1\r\n\
\r\n\
",
)
.expect("write 5");
thread::sleep(Duration::from_secs(6));
tcp.write_all(
b"\
Works: 0\r\n\
\r\n
",
)
.expect_err("write 6");
Expand All @@ -1629,7 +1629,7 @@ async fn header_read_timeout_slow_writes_multiple_requests() {
future::ready(Ok::<_, hyper::Error>(res))
}),
);
conn.without_shutdown().await.expect_err("header timeout");
assert!(conn.without_shutdown().await.unwrap_err().is_timeout());
}

#[tokio::test]
Expand Down

0 comments on commit 9604f25

Please sign in to comment.