You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
test(handlers): stop sleeping 10 ms in the NIP-05 metadata tests - #1391
The NIP-05 metadata tests in event-message-handler.spec.ts waited a real 10 ms after each call (setTimeout(resolve, 10)), 27 times. They now wait for one turn of the event loop (setImmediate), which the repo already does in worker-factory.spec.ts. The suite runs in about 205 ms instead of about 590 ms.
The issue asks for at least 20% less execution time while keeping coverage. I profiled the suite with mocha's JSON reporter: it has 257 tests, and the 27 sleeps account for most of its time (about 270 ms of about 420 ms spent in tests). The other bottlenecks the issue lists (signature verification, proof of work, database calls) are not slow here: no test takes more than about 18 ms apart from these waits.
processNip05Metadata is started without being awaited, and every collaborator the tests give it is a stub that resolves immediately, so the work is finished well before the next turn of the event loop. The tests that assert something was not called wait the same way.
How Has This Been Tested?
The spec run alone, five times each: 565, 588, 605, 611 and 577 ms before, 202, 244, 203, 207 and 200 ms after (mocha's reported time), a reduction of about 65%. 257 tests pass in both, none added or removed.
The spec passed 25 runs in a row after the change.
pnpm run test:unit (3775 passing), pnpm lint, pnpm run build:check, pnpm run check:deps, commitlint and changeset status. pnpm check:format reports 169 errors on main already; none are in this file, and biome format on it is clean.
Screenshots (if appropriate):
Types of changes
Non-functional change (docs, style, minor refactor)
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to change)
Checklist:
My code follows the code style of this project.
My change requires a change to the documentation.
I have updated the documentation accordingly.
I have read the CONTRIBUTING document.
I have added tests to cover my code changes.
I added a changeset, or this is docs-only and I added an empty changeset.
All new and existing tests passed.
Summary by CodeRabbit
Tests
Updated automated checks for event metadata processing to use more consistent asynchronous timing.
The scenarios and expected results remain unchanged; no user-facing behavior changes are included.
No actionable comments were generated in the recent review.
Walkthrough
The NIP-05 metadata-processing tests replace 10 ms timer waits with setImmediate waits. The test scenarios and assertions remain unchanged. A changeset file gains two YAML document separators with a blank line between them.
Changes: NIP-05 Test Wait Updates
Layer / File(s)
Summary
Update asynchronous test waits test/unit/handlers/event-message-handler.spec.ts, .changeset/event-message-handler-spec-speed.md
The NIP-05 metadata tests use setImmediate instead of 10 ms timers. Their scenarios and assertions remain unchanged. The changeset file gains two YAML document separators with a blank line between them.
This change only speeds up unit tests and adds an empty changeset. It does not alter runtime behavior, and no merge-blocking risk was identified.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: the NIP-05 metadata tests in event-message-handler.spec.ts no longer sleep 10 ms per wait. The type prefix 'test(handlers):' matches the test-only change. The changese…
Linked Issues check
Issue #609 asks for at least 20% less execution time in event-message-handler.spec.ts while keeping coverage. The diff changes 27 waits in the NIP-05 metadata tests from setTimeout(resolve, 10) to set…
Out of Scope Changes check
All changes support issue #609. The spec file changes are limited to the wait mechanism in the NIP-05 metadata tests. The changeset file .changeset/event-message-handler-spec-speed.md adds an empty ch…
Full details: Title check
Explanation
The title names the main change: the NIP-05 metadata tests in event-message-handler.spec.ts no longer sleep 10 ms per wait. The type prefix 'test(handlers):' matches the test-only change. The changeset adds only a YAML separator fix, which is minor and does not conflict with the title.
Full details: Linked Issues check
Explanation
Issue #609 asks for at least 20% less execution time in event-message-handler.spec.ts while keeping coverage. The diff changes 27 waits in the NIP-05 metadata tests from setTimeout(resolve, 10) to setImmediate(resolve). This removes about 270 ms of fixed sleep time per run. No test, assertion, or scenario is removed or altered, so coverage is unchanged. The author reports a measured suite time drop from about 590 ms to about 205 ms (about 65%). I did not rerun the suite, so the timing figures are author-reported. The reduction is well above the 20% target. The issue's other listed bottlenecks are described as potential causes. The requirement is the time target, so addressing the largest measured cause is sufficient. One residual risk: each test relies on processNip05Metadata finishing within one event-loop turn. The author states that its collaborators are immediately resolving stubs. The diff does not show this, and I did not inspect processNip05Metadata. The spec passing 25 consecutive runs supports this.
Full details: Out of Scope Changes check
Explanation
All changes support issue #609. The spec file changes are limited to the wait mechanism in the NIP-05 metadata tests. The changeset file .changeset/event-message-handler-spec-speed.md adds an empty changeset (front matter with no package entries). The PR description states that an empty changeset is intended for this non-functional change. No production code, unrelated tests, or unrelated files are changed.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
A rabbit taps the clock once, then hops away, setImmediate brings the tests along their way. The checks stay steady, assertions still align, Two separators mark the changeset line. The rabbit rests as faster waits unwind.
Recent review info
Automatic approval policy
Commit: 40d0d486d7b8.
Setting
Effective value
Source
Automatic approvals
Enabled
Global configuration
Merge risk
Minimal
Global configuration
Security risk
Not set
Global configuration
Not set means no limit was configured after inheritance. Use @coderabbitai configuration to inspect the resolved settings and their sources.
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: af875524-2202-492d-9138-b5195d27bc36
Commits
Reviewing files that changed from the base of the PR and between 0da5ca8 and 40d0d48.
Files selected for processing: 2
.changeset/event-message-handler-spec-speed.md
test/unit/handlers/event-message-handler.spec.ts
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
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
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.
Description
The NIP-05 metadata tests in
event-message-handler.spec.tswaited a real 10 ms after each call (setTimeout(resolve, 10)), 27 times. They now wait for one turn of the event loop (setImmediate), which the repo already does inworker-factory.spec.ts. The suite runs in about 205 ms instead of about 590 ms.Related Issue
Closes #609
Motivation and Context
The issue asks for at least 20% less execution time while keeping coverage. I profiled the suite with mocha's JSON reporter: it has 257 tests, and the 27 sleeps account for most of its time (about 270 ms of about 420 ms spent in tests). The other bottlenecks the issue lists (signature verification, proof of work, database calls) are not slow here: no test takes more than about 18 ms apart from these waits.
processNip05Metadatais started without being awaited, and every collaborator the tests give it is a stub that resolves immediately, so the work is finished well before the next turn of the event loop. The tests that assert something was not called wait the same way.How Has This Been Tested?
pnpm run test:unit(3775 passing),pnpm lint,pnpm run build:check,pnpm run check:deps, commitlint andchangeset status.pnpm check:formatreports 169 errors onmainalready; none are in this file, andbiome formaton it is clean.Screenshots (if appropriate):
Types of changes
Checklist:
Summary by CodeRabbit