mirror of
https://github.com/herdrdev/herdr.git
synced 2026-11-06 00:06:18 +00:00
test: stabilize plugin worker lease test (#5467)
The lease test spawned PowerShell on Windows and allowed five seconds for the worker's first ready marker. On a loaded Windows runner PowerShell startup alone consumed that budget, so the test failed at the readiness deadline even though the worker started normally. Run the worker as the test binary itself instead. The child is a native process with no shell startup, and it performs the same ready/release/result file handshake from the checkout directory. Cover the child with an ignored test spawned through `--exact ... --ignored`. The child returns immediately when no handshake request exists, so a direct `cargo test -- --ignored` run stays green.
This commit is contained in:
+36
-17
@@ -2741,23 +2741,15 @@ command = ["sh", "-c", "printf %s ${{HERDR_PANE_ID-unset}} > '{}'; sleep 1"]
|
||||
crate::persist::plugin_registry::update(|entries| *entries = vec![plugin.clone()]).unwrap();
|
||||
let mut app = test_app();
|
||||
crate::plugin_installations::load(&mut app.plugin_installation_leases).unwrap();
|
||||
let command = if cfg!(windows) {
|
||||
vec![
|
||||
"powershell.exe",
|
||||
"-NoProfile",
|
||||
"-Command",
|
||||
"Set-Content ready ready; $deadline = [DateTime]::UtcNow.AddSeconds(10); while (!(Test-Path release) -and [DateTime]::UtcNow -lt $deadline) { Start-Sleep -Milliseconds 10 }; Get-Content payload | Set-Content result",
|
||||
]
|
||||
} else {
|
||||
vec![
|
||||
"sh",
|
||||
"-c",
|
||||
"printf ready > ready; i=0; while [ ! -f release ] && [ $i -lt 500 ]; do sleep 0.02; i=$((i+1)); done; cat payload > result",
|
||||
]
|
||||
}
|
||||
.into_iter()
|
||||
.map(str::to_string)
|
||||
.collect();
|
||||
let command = vec![
|
||||
std::env::current_exe()
|
||||
.unwrap()
|
||||
.to_string_lossy()
|
||||
.into_owned(),
|
||||
"--exact".to_string(),
|
||||
"app::api::plugins::tests::plugin_worker_lease_child".to_string(),
|
||||
"--ignored".to_string(),
|
||||
];
|
||||
app.start_plugin_command(
|
||||
&plugin,
|
||||
None,
|
||||
@@ -2801,6 +2793,33 @@ command = ["sh", "-c", "printf %s ${{HERDR_PANE_ID-unset}} > '{}'; sleep 1"]
|
||||
std::fs::remove_dir_all(base).unwrap();
|
||||
}
|
||||
|
||||
/// Child half of `running_plugin_command_keeps_its_files_after_app_teardown`.
|
||||
///
|
||||
/// The plugin worker has to outlive the app, so the lease test spawns this
|
||||
/// test binary as the worker command. A native child starts reliably on
|
||||
/// loaded runners, unlike a shell that has to initialize first.
|
||||
#[test]
|
||||
#[ignore = "spawned as a plugin worker by running_plugin_command_keeps_its_files_after_app_teardown"]
|
||||
fn plugin_worker_lease_child() {
|
||||
// The lease test writes the handshake request into the worker directory
|
||||
// before starting the worker. A direct `cargo test -- --ignored` run has
|
||||
// no request, so it returns instead of waiting for a release file.
|
||||
if !std::path::Path::new("payload").exists() {
|
||||
return;
|
||||
}
|
||||
std::fs::write("ready", "ready").unwrap();
|
||||
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(10);
|
||||
while !std::path::Path::new("release").exists() {
|
||||
assert!(
|
||||
std::time::Instant::now() < deadline,
|
||||
"plugin worker waited too long for release"
|
||||
);
|
||||
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||
}
|
||||
let payload = std::fs::read_to_string("payload").unwrap();
|
||||
std::fs::write("result", payload).unwrap();
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn manifest_action_invoke_runs_command_and_captures_log() {
|
||||
|
||||
Reference in New Issue
Block a user