-
Notifications
You must be signed in to change notification settings - Fork 5k
bun test: attribute late expect() calls of an abandoned test to that test instead of the next one #38880
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
Open
robobun
wants to merge
9
commits into
main
Choose a base branch
from
farm/bec34389/snapshot-stale-test-attribution
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
bun test: attribute late expect() calls of an abandoned test to that test instead of the next one #38880
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4722cef
bun test: attribute late expect() calls of an abandoned test to that …
robobun 645b968
bun test: keep what a callback does to the async context; only take t…
robobun b7f1c9d
bun test: trim the comments around AsyncContextRef
robobun 764fbb3
bun test: name the matcher in expect.hasAssertions() errors; cover la…
robobun 7a90379
bun test: ignore the runner's own ref when registering callbacks; reb…
robobun 96f46f4
bun test: scope the timed-out hook of the snapshot test to one test; …
robobun 3ed7956
bun test: reject hooks registered by an abandoned invocation; drop th…
robobun 9364ef2
ci: retrigger
robobun 25fd236
event loop: remove run_callback_with_result_and_forcefully_drain_micr…
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| //! Put into the async context for the duration of one test or hook invocation, | ||
| //! so that the invocation's continuations can still be traced back to it. | ||
| //! | ||
| //! `expect()`, the snapshot matchers, `expect.assertions()` and hook registration | ||
| //! belong to whatever entry the runner is executing when they are called. Once | ||
| //! the runner has abandoned an invocation that is still running (timeout, or an | ||
| //! unhandled error while it was awaiting), that would be the next entry; | ||
| //! `RefData::abandoned` makes `bun_test::caller_ref` attribute such late calls | ||
| //! to the abandoned invocation instead, which rejects them. Invocations that | ||
| //! completed are never consulted, so callbacks they registered keep belonging to | ||
| //! whichever entry runs them. Uncaught errors are not covered: by the time one is | ||
| //! reported (`jest::on_unhandled_rejection`) the context it was thrown in is gone. | ||
| //! | ||
| //! The slot manipulation lives next to `AsyncContextFrame` (AsyncContextFrame.cpp). | ||
|
robobun marked this conversation as resolved.
robobun marked this conversation as resolved.
|
||
|
|
||
| use bun_jsc::{JSGlobalObject, JSValue, JsClass as _, JsResult}; | ||
|
|
||
| use crate::test_runner::bun_test::RefDataPtr; | ||
|
|
||
| #[bun_jsc::JsClass(no_construct, no_constructor)] // codegen wires to_js / from_js | ||
| pub struct AsyncContextRef { | ||
| /// Owned `+1`, released in `finalize`. | ||
| r#ref: RefDataPtr, | ||
| } | ||
|
|
||
| impl AsyncContextRef { | ||
| // Codegen calls `finalize(Box<Self>)`; clippy::boxed_local is a false positive. | ||
| #[allow(clippy::boxed_local)] | ||
| pub fn finalize(self: Box<Self>) { | ||
| self.r#ref.deref(); // `RefPtr` has no `Drop` | ||
| } | ||
|
|
||
| /// Puts `refdata` (a `+1`, consumed) into the context `callback` is about to | ||
| /// run with, and returns what to invoke in its place. Pair with [`Self::leave`]. | ||
|
robobun marked this conversation as resolved.
|
||
| pub(crate) fn enter(global: &JSGlobalObject, callback: JSValue, refdata: RefDataPtr) -> JsResult<JSValue> { | ||
| let ref_js = AsyncContextRef { r#ref: refdata }.to_js(global); | ||
| let callable = bun_jsc::cpp::Bun__AsyncContextRef__enter(global, callback, ref_js); | ||
| ref_js.ensure_still_alive(); | ||
| callable | ||
| } | ||
|
|
||
| /// Call once the callback returned, before its microtasks run. | ||
| pub(crate) fn leave(global: &JSGlobalObject) -> JsResult<()> { | ||
| bun_jsc::cpp::Bun__AsyncContextRef__leave(global) | ||
| } | ||
|
|
||
| /// A `+1` to the abandoned invocation the running JS descends from, if any. | ||
| pub(crate) fn abandoned_caller(global: &JSGlobalObject) -> Option<RefDataPtr> { | ||
| Self::abandoned_in_context(global).map(RefDataPtr::dupe_ref) | ||
| } | ||
|
|
||
| pub(crate) fn caller_is_abandoned(global: &JSGlobalObject) -> bool { | ||
| Self::abandoned_in_context(global).is_some() | ||
| } | ||
|
|
||
| /// To use right away: the borrow is of a wrapper that the context array | ||
| /// installed at this moment keeps alive. | ||
|
robobun marked this conversation as resolved.
|
||
| fn abandoned_in_context(global: &JSGlobalObject) -> Option<&RefDataPtr> { | ||
| let this = Self::from_js(bun_jsc::cpp::Bun__AsyncContextRef__current(global))?; | ||
| // SAFETY: live payload of the wrapper `__current` just found in the context array. | ||
| let refdata: &RefDataPtr = unsafe { &(*this).r#ref }; | ||
| refdata.abandoned.get().then_some(refdata) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.