Skip to content
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

fix(cli): show asserts before leaks #22904

Merged
merged 4 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 14 additions & 6 deletions cli/tools/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,19 @@ async fn run_tests_for_worker_inner(
}
};

// Check the result before we check for leaks
let result = {
let scope = &mut worker.js_runtime.handle_scope();
let result = v8::Local::new(scope, result);
serde_v8::from_v8::<TestResult>(scope, result)?
};
if matches!(result, TestResult::Failed(_)) {
fail_fast_tracker.add_failure();
let elapsed = earlier.elapsed().as_millis();
sender.send(TestEvent::Result(desc.id, result, elapsed as u64))?;
continue;
}

// Await activity stabilization
if let Some(diff) = wait_for_activity_to_stabilize(
worker,
Expand All @@ -806,6 +819,7 @@ async fn run_tests_for_worker_inner(
let (formatted, trailer_notes) = format_sanitizer_diff(diff);
if !formatted.is_empty() {
let failure = TestFailure::Leaked(formatted, trailer_notes);
fail_fast_tracker.add_failure();
let elapsed = earlier.elapsed().as_millis();
sender.send(TestEvent::Result(
desc.id,
Expand All @@ -816,12 +830,6 @@ async fn run_tests_for_worker_inner(
}
}

let scope = &mut worker.js_runtime.handle_scope();
let result = v8::Local::new(scope, result);
let result = serde_v8::from_v8::<TestResult>(scope, result)?;
if matches!(result, TestResult::Failed(_)) {
fail_fast_tracker.add_failure();
}
let elapsed = earlier.elapsed().as_millis();
sender.send(TestEvent::Result(desc.id, result, elapsed as u64))?;
}
Expand Down
5 changes: 5 additions & 0 deletions tests/specs/test/sanitizer_with_error/__test__.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"args": "test --quiet --reload main.js",
"output": "main.out",
"exitCode": 1
}
6 changes: 6 additions & 0 deletions tests/specs/test/sanitizer_with_error/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Deno.test(async function throws() {
// Leak
setTimeout(() => {}, 60_000);
// But the exception should mask the leak
throw new Error("Throws");
});
18 changes: 18 additions & 0 deletions tests/specs/test/sanitizer_with_error/main.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
running 1 test from ./main.js
throws ... FAILED (1ms)

ERRORS

throws => ./main.js:1:6
error: Error: Throws
throw new Error("Throws");
^
at throws ([WILDCARD]/main.js:5:9)

FAILURES

throws => ./main.js:1:6

FAILED | 0 passed | 1 failed (5ms)

error: Test failed