From 1edfa9180b07f6ebfe5062286c0269fa3db96e1a Mon Sep 17 00:00:00 2001 From: Vladislav Kuzmin <67874880+principalwater@users.noreply.github.com> Date: Sat, 28 Nov 2026 02:09:47 +0300 Subject: [PATCH] test(profiler): wait for profiled loop work before stopping (#6588) a_stopped_run_still_writes_its_profile sent SIGINT right after the fixture printed done, which could land before the loop ran, so the profile held only the initial fib(22) calls and the 'the loop ran' assertion failed. The fixture now prints looped after its first fib(18), and the test stops the run only after reading it, then checks for both completed passes. Fixes #6585 Co-authored-by: principalwater <67874880+principalwater@users.noreply.github.com> --- crates/ide-profiler/tests/python_cprofile.rs | 12 ++++++++---- fixtures/python-profiling/cpu_heavy.py | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/crates/ide-profiler/tests/python_cprofile.rs b/crates/ide-profiler/tests/python_cprofile.rs index c3de9f3aae..55e1e0a4b6 100644 --- a/crates/ide-profiler/tests/python_cprofile.rs +++ b/crates/ide-profiler/tests/python_cprofile.rs @@ -80,12 +80,16 @@ fn a_stopped_run_still_writes_its_profile() { let out = tempfile::tempdir().unwrap(); let (mut cmd, spec) = plan(&python, &["cpu_heavy.py", "--loop"], out.path()); let mut child = cmd.spawn().unwrap(); - let mut line = String::new(); - BufReader::new(child.stdout.take().unwrap()).read_line(&mut line).unwrap(); - assert_eq!(line.trim(), "done"); + let mut stdout = BufReader::new(child.stdout.take().unwrap()); + for marker in ["done", "looped"] { + let mut line = String::new(); + stdout.read_line(&mut line).unwrap(); + assert_eq!(line.trim(), marker); + } // What the first Stop sends. assert!(Command::new("kill").args(["-INT", &child.id().to_string()]).status().unwrap().success()); child.wait().unwrap(); let p = collect(&spec).unwrap(); - assert!(method(&p, "fib").calls.unwrap() > 57313.0, "the loop ran"); + // One completed fib(22) followed by one completed fib(18). + assert!(method(&p, "fib").calls.unwrap() >= 65_674.0, "both completed passes were profiled"); } diff --git a/fixtures/python-profiling/cpu_heavy.py b/fixtures/python-profiling/cpu_heavy.py index 776fc200bd..17644f0c57 100644 --- a/fixtures/python-profiling/cpu_heavy.py +++ b/fixtures/python-profiling/cpu_heavy.py @@ -28,8 +28,11 @@ def main(): primes(20000) checksum(str(i) for i in range(200000)) print("done", flush=True) - while "--loop" in sys.argv: + if "--loop" in sys.argv: fib(18) + print("looped", flush=True) + while True: + fib(18) if __name__ == "__main__":