Shorten --max-time in tests and use a more stable error check (#14494)

- fixes flakey tests from solving #14241

# Description
This is a preliminary fix for the flaky tests and also
shortened the `--max-time` in the tests.

# User-Facing Changes
<!-- List of all changes that impact the user experience here. This
helps us keep track of breaking changes. -->



---------

Signed-off-by: Alex Kattathra Johnson <alex.kattathra.johnson@gmail.com>
This commit is contained in:
Alex Kattathra Johnson 2024-12-06 06:03:13 -06:00 committed by GitHub
parent 81d68cd478
commit cda9ae1e42
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 69 additions and 24 deletions

View File

@ -131,14 +131,21 @@ fn http_delete_timeout() {
let _mock = server
.mock("DELETE", "/")
.with_chunked_body(|w| {
thread::sleep(Duration::from_secs(1));
thread::sleep(Duration::from_secs(10));
w.write_all(b"Delayed response!")
})
.create();
let actual = nu!(pipeline(
format!("http delete --max-time 500ms {url}", url = server.url()).as_str()
format!("http delete --max-time 100ms {url}", url = server.url()).as_str()
));
assert!(&actual.err.contains("nu::shell::io_error"));
assert!(&actual.err.contains("nu::shell::network_failure"));
#[cfg(not(target_os = "windows"))]
assert!(&actual.err.contains("timed out reading response"));
#[cfg(target_os = "windows")]
assert!(&actual
.err
.contains("did not properly respond after a period of time"));
}

View File

@ -325,14 +325,21 @@ fn http_get_timeout() {
let _mock = server
.mock("GET", "/")
.with_chunked_body(|w| {
thread::sleep(Duration::from_secs(1));
thread::sleep(Duration::from_secs(10));
w.write_all(b"Delayed response!")
})
.create();
let actual = nu!(pipeline(
format!("http get --max-time 500ms {url}", url = server.url()).as_str()
format!("http get --max-time 100ms {url}", url = server.url()).as_str()
));
assert!(&actual.err.contains("nu::shell::io_error"));
assert!(&actual.err.contains("nu::shell::network_failure"));
#[cfg(not(target_os = "windows"))]
assert!(&actual.err.contains("timed out reading response"));
#[cfg(target_os = "windows")]
assert!(&actual
.err
.contains("did not properly respond after a period of time"));
}

View File

@ -50,14 +50,21 @@ fn http_options_timeout() {
let _mock = server
.mock("OPTIONS", "/")
.with_chunked_body(|w| {
thread::sleep(Duration::from_secs(1));
thread::sleep(Duration::from_secs(10));
w.write_all(b"Delayed response!")
})
.create();
let actual = nu!(pipeline(
format!("http options --max-time 500ms {url}", url = server.url()).as_str()
format!("http options --max-time 100ms {url}", url = server.url()).as_str()
));
assert!(&actual.err.contains("nu::shell::io_error"));
assert!(&actual.err.contains("nu::shell::network_failure"));
#[cfg(not(target_os = "windows"))]
assert!(&actual.err.contains("timed out reading response"));
#[cfg(target_os = "windows")]
assert!(&actual
.err
.contains("did not properly respond after a period of time"));
}

View File

@ -171,18 +171,25 @@ fn http_patch_timeout() {
let _mock = server
.mock("PATCH", "/")
.with_chunked_body(|w| {
thread::sleep(Duration::from_secs(1));
thread::sleep(Duration::from_secs(10));
w.write_all(b"Delayed response!")
})
.create();
let actual = nu!(pipeline(
format!(
"http patch --max-time 500ms {url} patchbody",
"http patch --max-time 100ms {url} patchbody",
url = server.url()
)
.as_str()
));
assert!(&actual.err.contains("nu::shell::io_error"));
assert!(&actual.err.contains("nu::shell::network_failure"));
#[cfg(not(target_os = "windows"))]
assert!(&actual.err.contains("timed out reading response"));
#[cfg(target_os = "windows")]
assert!(&actual
.err
.contains("did not properly respond after a period of time"));
}

View File

@ -285,18 +285,25 @@ fn http_post_timeout() {
let _mock = server
.mock("POST", "/")
.with_chunked_body(|w| {
thread::sleep(Duration::from_secs(1));
thread::sleep(Duration::from_secs(10));
w.write_all(b"Delayed response!")
})
.create();
let actual = nu!(pipeline(
format!(
"http post --max-time 500ms {url} postbody",
"http post --max-time 100ms {url} postbody",
url = server.url()
)
.as_str()
));
assert!(&actual.err.contains("nu::shell::io_error"));
assert!(&actual.err.contains("nu::shell::network_failure"));
#[cfg(not(target_os = "windows"))]
assert!(&actual.err.contains("timed out reading response"));
#[cfg(target_os = "windows")]
assert!(&actual
.err
.contains("did not properly respond after a period of time"));
}

View File

@ -171,18 +171,25 @@ fn http_put_timeout() {
let _mock = server
.mock("PUT", "/")
.with_chunked_body(|w| {
thread::sleep(Duration::from_secs(1));
thread::sleep(Duration::from_secs(10));
w.write_all(b"Delayed response!")
})
.create();
let actual = nu!(pipeline(
format!(
"http put --max-time 500ms {url} putbody",
"http put --max-time 100ms {url} putbody",
url = server.url()
)
.as_str()
));
assert!(&actual.err.contains("nu::shell::io_error"));
assert!(&actual.err.contains("nu::shell::network_failure"));
#[cfg(not(target_os = "windows"))]
assert!(&actual.err.contains("timed out reading response"));
#[cfg(target_os = "windows")]
assert!(&actual
.err
.contains("did not properly respond after a period of time"));
}

View File

@ -1544,8 +1544,8 @@ impl From<io::Error> for ShellError {
impl From<Spanned<io::Error>> for ShellError {
fn from(error: Spanned<io::Error>) -> Self {
let Spanned { item: error, span } = error;
if error.kind() == io::ErrorKind::Other {
match error.into_inner() {
match error.kind() {
io::ErrorKind::Other => match error.into_inner() {
Some(err) => match err.downcast() {
Ok(err) => *err,
Err(err) => Self::IOErrorSpanned {
@ -1557,12 +1557,15 @@ impl From<Spanned<io::Error>> for ShellError {
msg: "unknown error".into(),
span,
},
}
} else {
Self::IOErrorSpanned {
},
io::ErrorKind::TimedOut => Self::NetworkFailure {
msg: error.to_string(),
span,
}
},
_ => Self::IOErrorSpanned {
msg: error.to_string(),
span,
},
}
}
}