Skip to content

test(handlers): stop sleeping 10 ms in the NIP-05 metadata tests - #1391

Merged
cameri merged 1 commit into
cameri:mainfrom
Priyanshubhartistm:perf/event-message-handler-spec-speed
Dec 4, 2026
Merged

cameri merged 1 commit into
cameri:mainfrom
Priyanshubhartistm:perf/event-message-handler-spec-speed

Conversation

@Priyanshubhartistm

@Priyanshubhartistm Priyanshubhartistm commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Description

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.

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.

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.

Signed-off-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
@changeset-bot

changeset-bot Bot commented Dec 4, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 40d0d48

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Explain Change →

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.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Other

Merge Risk: Minimal · up to 40d0d

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: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 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 Passed 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 Passed 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.

Share

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.

@greptile-apps

greptile-apps Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5RetriggerView in Greptile

[Low impact] This PR appears safe to merge.

Summary

Replaces 27 fixed 10 ms waits with setImmediate in the NIP-05 metadata tests.

  • NIP-05 metadata tests finish their async checks without a fixed 10 ms wait.

Reviews (1) · Last reviewed commit: "test(handlers): stop sleeping 10 ms in t..." · Reviewed by Greptile

@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 47404661792

Coverage remained the same at 81.081%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 15713
Covered Lines: 13252
Line Coverage: 84.34%
Relevant Branches: 8696
Covered Branches: 6539
Branch Coverage: 75.2%
Branches in Coverage %: Yes
Coverage Strength: 705.67 hits per line

💛 - Coveralls

@cameri
cameri merged commit ccf2cb9 into cameri:main Dec 4, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize unit tests: event-message-handler.spec.ts

3 participants