Repository navigation
fix(geolibre): check Cancel before starting the runner #2182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,11 +149,11 @@ fn output_within(c: Command, limit: Duration) -> Option<Output> { | |
| fn spawn_when_free(c: &mut Command, stop: &dyn Fn() -> Option<String>) -> Result<std::process::Child, String> { | ||
| let start = Instant::now(); | ||
| loop { | ||
| if let Some(why) = stop() { | ||
| return Err(why); | ||
| } | ||
|
Comment on lines
+152
to
+154
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep a test that stops a child after it starts. The pre-spawn stop check now returns before Let the predicate return Suggested test change
|
||
| match c.spawn() { | ||
| Err(e) if e.kind() == std::io::ErrorKind::ExecutableFileBusy && start.elapsed() < Duration::from_secs(1) => { | ||
| if let Some(why) = stop() { | ||
| return Err(why); | ||
| } | ||
| std::thread::sleep(Duration::from_millis(10)); | ||
| } | ||
| Err(e) => return Err(e.to_string()), | ||
|
|
@@ -393,25 +393,6 @@ fn stop_reason(live: &dyn Fn() -> Result<(), String>) -> Option<String> { | |
| mod tests { | ||
| use super::*; | ||
|
|
||
| /// Runner versions 1.x are used; anything else, or a version that can't be read, isn't, and | ||
| /// the reason names the runner, its version and the supported range. | ||
| #[test] | ||
| fn supported_runner_versions() { | ||
| for ok in ["geolibre-cli 1.0.0", "geolibre-cli 1.8.0", "geolibre-cli v1.8.2", "geolibre-cli 1.9.0-dev", "geolibre-cli 1.99.3+abc"] { | ||
| assert_eq!(check_supported("r", ok), Ok(()), "{ok}"); | ||
| } | ||
| for bad in ["geolibre-cli 2.0.0", "geolibre-cli 2.0.0-rc.1", "geolibre-cli 0.11.0"] { | ||
| let e = check_supported("/opt/geolibre", bad).unwrap_err(); | ||
| assert!(e.contains("/opt/geolibre") && e.contains(bad) && e.contains("1.0.0") && e.contains("2.0.0"), "{e}"); | ||
| } | ||
| for unreadable in ["geolibre-cli", "geolibre-cli 1.8", "geolibre-cli 1.8.0.1", "geolibre-cli one"] { | ||
| assert!(check_supported("r", unreadable).unwrap_err().contains("can't read"), "{unreadable}"); | ||
| } | ||
| assert!(download_url().ends_with(&format!("/releases/tag/v{RELEASE}"))); | ||
| let pinned = parse_version(&format!("geolibre-cli {RELEASE}")).unwrap(); | ||
| assert!(pinned >= SUPPORTED_FROM && pinned < SUPPORTED_BEFORE, "the pinned release is supported"); | ||
| } | ||
|
|
||
| /// Discovery passes over a runner outside the supported range for the next supported one, | ||
| /// and says why; with only an unsupported one, there is no runner but the reason is given. | ||
| #[test] | ||
|
|
@@ -492,3 +473,36 @@ mod tests { | |
| assert_eq!(with_still(std::sync::Arc::new(|| true), || stop_reason(&fine)), None); | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod portable_tests { | ||
| use super::*; | ||
|
|
||
| /// A stopped run is refused before attempting even an invalid executable. This also keeps | ||
| /// every busy-file retry behind the same cancellation check. | ||
| #[test] | ||
| fn stopped_run_never_attempts_to_spawn() { | ||
| let mut command = Command::new(""); | ||
| let error = spawn_when_free(&mut command, &|| Some("cancelled before spawn".to_string())).unwrap_err(); | ||
| assert_eq!(error, "cancelled before spawn"); | ||
| } | ||
|
|
||
| /// Runner versions 1.x are used; anything else, or a version that can't be read, isn't, and | ||
| /// the reason names the runner, its version and the supported range. | ||
| #[test] | ||
| fn supported_runner_versions() { | ||
| for ok in ["geolibre-cli 1.0.0", "geolibre-cli 1.8.0", "geolibre-cli v1.8.2", "geolibre-cli 1.9.0-dev", "geolibre-cli 1.99.3+abc"] { | ||
| assert_eq!(check_supported("r", ok), Ok(()), "{ok}"); | ||
| } | ||
| for bad in ["geolibre-cli 2.0.0", "geolibre-cli 2.0.0-rc.1", "geolibre-cli 0.11.0"] { | ||
| let e = check_supported("/opt/geolibre", bad).unwrap_err(); | ||
| assert!(e.contains("/opt/geolibre") && e.contains(bad) && e.contains("1.0.0") && e.contains("2.0.0"), "{e}"); | ||
| } | ||
| for unreadable in ["geolibre-cli", "geolibre-cli 1.8", "geolibre-cli 1.8.0.1", "geolibre-cli one"] { | ||
| assert!(check_supported("r", unreadable).unwrap_err().contains("can't read"), "{unreadable}"); | ||
| } | ||
| assert!(download_url().ends_with(&format!("/releases/tag/v{RELEASE}"))); | ||
| let pinned = parse_version(&format!("geolibre-cli {RELEASE}")).unwrap(); | ||
| assert!(pinned >= SUPPORTED_FROM && pinned < SUPPORTED_BEFORE, "the pinned release is supported"); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, two related points on this check (nothing blocking; confidence high on both):
The check narrows the window but doesn't close it. A Cancel that lands between
stop()returningNoneandc.spawn()still starts the program.output_untilthen kills it on its next 20 ms poll. The PR body's "a cancelled run cannot briefly launch a program" overstates this. Suggest wording like "a cancelled run is refused before the first spawn attempt; a Cancel that lands during the spawn is handled by the poll loop inoutput_until."The regression test
stopped_run_never_attempts_to_spawncovers only the first pre-spawn check. The busy-file retry path the PR mentions has no test. That's a test-coverage gap, and it's a quality point for the release quality pass.