From 2e4a1fc3e89d00e060ca9d747b6887dae215f0eb Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Fri, 1 Mar 2024 14:26:57 -0700 Subject: [PATCH] fix(cli): force flush output after test unloads (#22660) Fixes flake in load_unload test --- cli/tools/test/mod.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cli/tools/test/mod.rs b/cli/tools/test/mod.rs index 0f10188bc2..6b592f95e9 100644 --- a/cli/tools/test/mod.rs +++ b/cli/tools/test/mod.rs @@ -391,7 +391,7 @@ pub enum TestEvent { StepRegister(TestStepDescription), StepWait(usize), StepResult(usize, TestStepResult, u64), - /// Indicates that this worker has completed. + /// Indicates that this worker has completed running tests. Completed, /// Indicates that the user has cancelled the test run with Ctrl+C and /// the run should be aborted. @@ -513,7 +513,7 @@ pub async fn test_specifier( worker_factory, permissions, specifier.clone(), - &worker_sender.sender, + &mut worker_sender.sender, StdioPipe::file(worker_sender.stdout), StdioPipe::file(worker_sender.stderr), fail_fast_tracker, @@ -543,7 +543,7 @@ async fn test_specifier_inner( worker_factory: Arc, permissions: Permissions, specifier: ModuleSpecifier, - sender: &TestEventSender, + sender: &mut TestEventSender, stdout: StdioPipe, stderr: StdioPipe, fail_fast_tracker: FailFastTracker, @@ -592,6 +592,9 @@ async fn test_specifier_inner( worker.dispatch_beforeunload_event(located_script_name!())?; worker.dispatch_unload_event(located_script_name!())?; + // Ensure all output has been flushed + _ = sender.flush(); + // Ensure the worker has settled so we can catch any remaining unhandled rejections. We don't // want to wait forever here. worker.run_up_to_duration(Duration::from_millis(0)).await?;