From afce3805302b751db49772d25962df2fc4545542 Mon Sep 17 00:00:00 2001 From: Devyn Cairns Date: Mon, 11 Mar 2024 04:01:48 -0700 Subject: [PATCH] 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. --- tests/plugin_persistence/mod.rs | 36 +++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/tests/plugin_persistence/mod.rs b/tests/plugin_persistence/mod.rs index aca48c2890..9de3ff464c 100644 --- a/tests/plugin_persistence/mod.rs +++ b/tests/plugin_persistence/mod.rs @@ -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::().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::().expect("not a number"); + assert!( + nanos < 5_000_000_000, + "with inc-specific config: more than 5 seconds: {nanos} ns" + ); } #[test]