mirror of
https://github.com/nushell/nushell
synced 2025-01-14 06:04:09 +00:00
More robustness improvements to plugin persistence tests (#12185)
# Description These tests have been causing some pain, so I've done a few more things to try to make them a bit more tolerant of running slowly. - `plugin_process_exits_after_stop`: using timeout strategy, allows the process 5 seconds to exit. - generally don't use sleep to test anything less than 100ms # User-Facing Changes # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` # After Submitting
This commit is contained in:
parent
0ff36dfe42
commit
be841d88d7
1 changed files with 27 additions and 9 deletions
|
@ -44,15 +44,32 @@ fn plugin_process_exits_after_stop() {
|
||||||
r#"
|
r#"
|
||||||
"2.0.0" | inc -m | ignore
|
"2.0.0" | inc -m | ignore
|
||||||
let pid = (plugin list).0.pid
|
let pid = (plugin list).0.pid
|
||||||
ps | where pid == $pid | length | print
|
if (ps | where pid == $pid | is-empty) {
|
||||||
print ";"
|
error make {
|
||||||
|
msg: "plugin process not running initially"
|
||||||
|
}
|
||||||
|
}
|
||||||
plugin stop inc
|
plugin stop inc
|
||||||
sleep 10ms
|
let start = (date now)
|
||||||
ps | where pid == $pid | length | print
|
mut cond = true
|
||||||
|
while $cond {
|
||||||
|
sleep 100ms
|
||||||
|
$cond = (
|
||||||
|
(ps | where pid == $pid | is-not-empty) and
|
||||||
|
((date now) - $start) < 5sec
|
||||||
|
)
|
||||||
|
}
|
||||||
|
((date now) - $start) | into int
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
assert_eq!("1;0", out.out, "plugin process did not stop running");
|
|
||||||
assert!(out.status.success());
|
assert!(out.status.success());
|
||||||
|
|
||||||
|
let nanos = out.out.parse::<i64>().expect("not a number");
|
||||||
|
assert!(
|
||||||
|
nanos < 5_000_000_000,
|
||||||
|
"not stopped after more than 5 seconds: {nanos} ns"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -195,14 +212,15 @@ fn custom_values_can_still_be_collapsed_after_stop() {
|
||||||
#[test]
|
#[test]
|
||||||
fn plugin_gc_can_be_configured_to_stop_plugins_immediately() {
|
fn plugin_gc_can_be_configured_to_stop_plugins_immediately() {
|
||||||
// I know the test is to stop "immediately", but if we actually check immediately it could
|
// I know the test is to stop "immediately", but if we actually check immediately it could
|
||||||
// lead to a race condition. So there's a 1ms sleep just to be fair.
|
// lead to a race condition. Using 100ms sleep just because with contention we don't really
|
||||||
|
// know for sure how long this could take
|
||||||
let out = nu_with_plugins!(
|
let out = nu_with_plugins!(
|
||||||
cwd: ".",
|
cwd: ".",
|
||||||
plugin: ("nu_plugin_inc"),
|
plugin: ("nu_plugin_inc"),
|
||||||
r#"
|
r#"
|
||||||
$env.config.plugin_gc = { default: { stop_after: 0sec } }
|
$env.config.plugin_gc = { default: { stop_after: 0sec } }
|
||||||
"2.3.0" | inc -M
|
"2.3.0" | inc -M
|
||||||
sleep 1ms
|
sleep 100ms
|
||||||
(plugin list | where name == inc).0.is_running
|
(plugin list | where name == inc).0.is_running
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
@ -219,7 +237,7 @@ fn plugin_gc_can_be_configured_to_stop_plugins_immediately() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"2.3.0" | inc -M
|
"2.3.0" | inc -M
|
||||||
sleep 1ms
|
sleep 100ms
|
||||||
(plugin list | where name == inc).0.is_running
|
(plugin list | where name == inc).0.is_running
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
@ -325,7 +343,7 @@ fn plugin_gc_can_be_disabled_by_plugin() {
|
||||||
nu-example-disable-gc
|
nu-example-disable-gc
|
||||||
$env.config.plugin_gc = { default: { stop_after: 0sec } }
|
$env.config.plugin_gc = { default: { stop_after: 0sec } }
|
||||||
nu-example-1 1 foo | ignore # ensure we've run the plugin with the new config
|
nu-example-1 1 foo | ignore # ensure we've run the plugin with the new config
|
||||||
sleep 10ms
|
sleep 100ms
|
||||||
(plugin list | where name == example).0.is_running
|
(plugin list | where name == example).0.is_running
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue