Make the plugin persistence GC delay test more reliable (#12153)

# Description

This makes the test a bit more complicated, but implements a timeout
loop in the script. As long as the test completes in 5 seconds it's
considered to be ok. The default is 10 seconds, so that would still be
half that.

This should help with running on the busy CI where things sometimes take
a while. Unfortunately this is a timing sensitive test. The alternative
is basically to just not test this at all because it's too difficult to
guarantee that it will complete in time. If we continue to have issues,
I might just have to take that route instead.
This commit is contained in:
Devyn Cairns 2024-03-11 04:01:48 -07:00 committed by GitHub
parent 5596190377
commit afce380530
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -235,12 +235,24 @@ fn plugin_gc_can_be_configured_to_stop_plugins_after_delay() {
r#"
$env.config.plugin_gc = { default: { stop_after: 50ms } }
"2.3.0" | inc -M
sleep 100ms
(plugin list | where name == inc).0.is_running
let start = (date now)
mut cond = true
while $cond {
sleep 100ms
$cond = (
(plugin list | where name == inc).0.is_running and
((date now) - $start) < 5sec
)
}
((date now) - $start) | into int
"#
);
assert!(out.status.success());
assert_eq!("false", out.out, "with config as default");
let nanos = out.out.parse::<i64>().expect("not a number");
assert!(
nanos < 5_000_000_000,
"with config as default: more than 5 seconds: {nanos} ns"
);
let out = nu_with_plugins!(
cwd: ".",
@ -252,12 +264,24 @@ fn plugin_gc_can_be_configured_to_stop_plugins_after_delay() {
}
}
"2.3.0" | inc -M
sleep 100ms
(plugin list | where name == inc).0.is_running
let start = (date now)
mut cond = true
while $cond {
sleep 100ms
$cond = (
(plugin list | where name == inc).0.is_running and
((date now) - $start) < 5sec
)
}
((date now) - $start) | into int
"#
);
assert!(out.status.success());
assert_eq!("false", out.out, "with inc-specific config");
let nanos = out.out.parse::<i64>().expect("not a number");
assert!(
nanos < 5_000_000_000,
"with inc-specific config: more than 5 seconds: {nanos} ns"
);
}
#[test]