fix(test): randomBytes async callback test asserted pre-#6430 inline timing#6838
Open
TheHypnoo wants to merge 1 commit into
Open
fix(test): randomBytes async callback test asserted pre-#6430 inline timing#6838TheHypnoo wants to merge 1 commit into
TheHypnoo wants to merge 1 commit into
Conversation
…timing #6430 moved the async `randomBytes` callback onto a macrotask (`js_set_immediate_callback_args`) to match Node, which runs `randomBytes` on the libuv threadpool and fires `(err, buffer)` a loop iteration later. `native_dispatch_random_bytes_value_form_fires_callback` predates that change and still asserted the callback fired inline, so it has been red on `main` ever since. Update the test to match: assert the callback does not fire synchronously, pump the callback-timer queue, then check the delivered arguments. This locks in the macrotask timing instead of the behavior it replaced. The dispatch path itself is unchanged.
TheHypnoo
force-pushed
the
fix/random-bytes-async-test-macrotask
branch
from
July 25, 2026 16:08
76d6653 to
b17e095
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe random bytes native dispatch test now verifies callback execution on a macrotask, advances the callback timer queue, and validates the callback arguments. The changelog documents the test-only correction and confirms no runtime behavior changed. ChangesRandom bytes callback timing
Estimated code review effort: 1 (Trivial) | ~5 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
crypto::random::tests::native_dispatch_random_bytes_value_form_fires_callbackfails onmain(verified at8b2c736ed, macOS arm64):The other 96 tests in
perry-stdlibpass. A permanently red test in the per-crate CI scope teaches everyone to ignore that crate's results, so this closes it.Why it fails
The test's assumption broke — the dispatch path is fine.
#6430 moved the async
randomBytescallback onto a macrotask:That is correct and deliberate. Node runs
randomByteson the libuv threadpool, so the(err, buffer)callback fires a loop iteration later, never inline. The test predates #6430, asserted synchronous firing, and was never updated.The value-form dispatch itself still works: the
"randomBytes" if args_len >= 2arm routes tojs_crypto_random_bytes_async, the callback lands witherr = nulland a Buffer pointer — just one macrotask later.Change
Test only. Assert the callback does not fire inline, drain the callback-timer queue, then check the delivered arguments:
This locks in #6430's macrotask timing rather than the behavior it replaced.
Validation
./scripts/check_file_size.shOK.cargo fmt --allleaves this diff unchanged (it does reformatcrates/perry-hir/src/lower/builder_fold.rs, pre-existing drift onmain, left alone here).One thing worth knowing
CALLBACK_TIMERSis a process-global mutex, butagent::CURRENT_AGENTis thread-local and defaults toPRIMARY_AGENT, so everycargo testthread passesagent::owns(). A test that callsjs_callback_timer_tick()can therefore drain and run another test thread's immediates. That is safe today only because nothing else in theperry-stdliblib-test binary schedules callback timers (webcrypto/digest.rsschedules immediates but has no tests). Worth checking before a second timer-using test lands in this crate.No version bump, no
CHANGELOG.mdedit; changelog fragment added underchangelog.d/.Summary by CodeRabbit
Tests
crypto.randomBytescoverage to verify callbacks execute on a later task rather than synchronously.(error, buffer)results.Documentation