1
0
mirror of https://github.com/nushell/nushell.git synced 2025-07-14 05:15:23 +02:00

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

- fixes flakey tests from solving 

# 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
7 changed files with 69 additions and 24 deletions
crates
nu-command
nu-protocol

@ -131,14 +131,21 @@ fn http_delete_timeout() {
let _mock = server let _mock = server
.mock("DELETE", "/") .mock("DELETE", "/")
.with_chunked_body(|w| { .with_chunked_body(|w| {
thread::sleep(Duration::from_secs(1)); thread::sleep(Duration::from_secs(10));
w.write_all(b"Delayed response!") w.write_all(b"Delayed response!")
}) })
.create(); .create();
let actual = nu!(pipeline( 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"));
} }

@ -325,14 +325,21 @@ fn http_get_timeout() {
let _mock = server let _mock = server
.mock("GET", "/") .mock("GET", "/")
.with_chunked_body(|w| { .with_chunked_body(|w| {
thread::sleep(Duration::from_secs(1)); thread::sleep(Duration::from_secs(10));
w.write_all(b"Delayed response!") w.write_all(b"Delayed response!")
}) })
.create(); .create();
let actual = nu!(pipeline( 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"));
} }

@ -50,14 +50,21 @@ fn http_options_timeout() {
let _mock = server let _mock = server
.mock("OPTIONS", "/") .mock("OPTIONS", "/")
.with_chunked_body(|w| { .with_chunked_body(|w| {
thread::sleep(Duration::from_secs(1)); thread::sleep(Duration::from_secs(10));
w.write_all(b"Delayed response!") w.write_all(b"Delayed response!")
}) })
.create(); .create();
let actual = nu!(pipeline( 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"));
} }

@ -171,18 +171,25 @@ fn http_patch_timeout() {
let _mock = server let _mock = server
.mock("PATCH", "/") .mock("PATCH", "/")
.with_chunked_body(|w| { .with_chunked_body(|w| {
thread::sleep(Duration::from_secs(1)); thread::sleep(Duration::from_secs(10));
w.write_all(b"Delayed response!") w.write_all(b"Delayed response!")
}) })
.create(); .create();
let actual = nu!(pipeline( let actual = nu!(pipeline(
format!( format!(
"http patch --max-time 500ms {url} patchbody", "http patch --max-time 100ms {url} patchbody",
url = server.url() url = server.url()
) )
.as_str() .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"));
} }

@ -285,18 +285,25 @@ fn http_post_timeout() {
let _mock = server let _mock = server
.mock("POST", "/") .mock("POST", "/")
.with_chunked_body(|w| { .with_chunked_body(|w| {
thread::sleep(Duration::from_secs(1)); thread::sleep(Duration::from_secs(10));
w.write_all(b"Delayed response!") w.write_all(b"Delayed response!")
}) })
.create(); .create();
let actual = nu!(pipeline( let actual = nu!(pipeline(
format!( format!(
"http post --max-time 500ms {url} postbody", "http post --max-time 100ms {url} postbody",
url = server.url() url = server.url()
) )
.as_str() .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"));
} }

@ -171,18 +171,25 @@ fn http_put_timeout() {
let _mock = server let _mock = server
.mock("PUT", "/") .mock("PUT", "/")
.with_chunked_body(|w| { .with_chunked_body(|w| {
thread::sleep(Duration::from_secs(1)); thread::sleep(Duration::from_secs(10));
w.write_all(b"Delayed response!") w.write_all(b"Delayed response!")
}) })
.create(); .create();
let actual = nu!(pipeline( let actual = nu!(pipeline(
format!( format!(
"http put --max-time 500ms {url} putbody", "http put --max-time 100ms {url} putbody",
url = server.url() url = server.url()
) )
.as_str() .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"));
} }

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