Skip to content

Fix: Refactor streaming mode test to use modern async/await pattern#102

Merged
VikramAditya33 merged 1 commit into
FOSSFORGE:mainfrom
Ashwani1405:refactor-streaming-test
May 8, 2026
Merged

Fix: Refactor streaming mode test to use modern async/await pattern#102
VikramAditya33 merged 1 commit into
FOSSFORGE:mainfrom
Ashwani1405:refactor-streaming-test

Conversation

@Ashwani1405
Copy link
Copy Markdown

@Ashwani1405 Ashwani1405 commented May 8, 2026

Fixes #81

This PR refactored the streaming mode test to use async/await consistently instead of mixing done callbacks with async IIFE patterns.

Changes made:

  • Converted the test to async
  • Replaced done() flow with explicit promise awaiting
  • Added consumePromise for clearer async coordination

Summary by CodeRabbit

  • Tests
    • Refactored streaming test suite to use modern async patterns, improving test reliability and consistency for streaming behavior validation.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 8, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 80f77e08-9d91-49d4-82d7-0333e25785f0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/http/core/request.spec.ts`:
- Around line 1310-1314: The test currently calls jest.runAllTimers(); then
awaits consumePromise and finally calls jest.useRealTimers(), but if await
consumePromise throws the jest.useRealTimers() call is skipped; wrap the await
in a try/finally so jest.useRealTimers() always runs: call jest.runAllTimers(),
then try { await consumePromise; } finally { jest.useRealTimers(); }
(referencing consumePromise, jest.runAllTimers, and jest.useRealTimers to locate
the change).
- Around line 1309-1312: The test's async iterator uses setImmediate plus
Promises and currently calls jest.runAllTimers(), which can run timer callbacks
before microtasks and cause races; replace the call to jest.runAllTimers() with
await jest.runAllTimersAsync() (keeping the await before awaiting
consumePromise) so timer advances interleave microtask flushes properly — update
the invocation near the test that awaits consumePromise and references
setImmediate / consumePromise / the for await...of loop.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 558f9f95-d1b9-46fc-8cac-d3abe07d81fb

📥 Commits

Reviewing files that changed from the base of the PR and between 65e7cc6 and 4dae9a2.

📒 Files selected for processing (1)
  • src/http/core/request.spec.ts

Comment thread src/http/core/request.spec.ts Outdated
Comment thread src/http/core/request.spec.ts Outdated
Comment on lines 1310 to 1314
jest.runAllTimers();

await consumePromise;

jest.useRealTimers();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

jest.useRealTimers() is not called when consumePromise rejects — fake timers leak into subsequent tests.

If the expect(result).toBe('Hello World') assertion inside consumePromise fails (or any error is thrown within the IIFE), await consumePromise on Line 1312 re-throws, causing Line 1314 (jest.useRealTimers()) to be skipped entirely. Any later test in the same file will then run under fake timers, leading to silent hangs or spurious failures.

🛡️ Proposed fix: guard `useRealTimers` with `try/finally`
-      // Advance timers to trigger setImmediate
-      jest.runAllTimers();
-
-      await consumePromise;
-
-      jest.useRealTimers();
+      // Advance timers to trigger setImmediate
+      jest.runAllTimers();
+
+      try {
+        await consumePromise;
+      } finally {
+        jest.useRealTimers();
+      }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
jest.runAllTimers();
await consumePromise;
jest.useRealTimers();
jest.runAllTimers();
try {
await consumePromise;
} finally {
jest.useRealTimers();
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/http/core/request.spec.ts` around lines 1310 - 1314, The test currently
calls jest.runAllTimers(); then awaits consumePromise and finally calls
jest.useRealTimers(), but if await consumePromise throws the
jest.useRealTimers() call is skipped; wrap the await in a try/finally so
jest.useRealTimers() always runs: call jest.runAllTimers(), then try { await
consumePromise; } finally { jest.useRealTimers(); } (referencing consumePromise,
jest.runAllTimers, and jest.useRealTimers to locate the change).

@VikramAditya33
Copy link
Copy Markdown
Collaborator

@Ashwani1405 Consider the coderabbit suggestions for this since it's a test file we can take suggestion in consideration

runAllTimersAsync

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
B

test: ensure fake timers cleanup with finally
@Ashwani1405 Ashwani1405 force-pushed the refactor-streaming-test branch from 05733ac to bb3a74e Compare May 8, 2026 16:12
@Ashwani1405
Copy link
Copy Markdown
Author

Ashwani1405 commented May 8, 2026

Applied the CodeRabbit suggestions:

  • switched to jest.runAllTimersAsync() for better async timer handling
  • wrapped timer restoration in try/finally to avoid fake timer leakage on failures
  • Re-tested locally and all tests are passing.

Also, squashed commits to one.
@VikramAditya33

@VikramAditya33
Copy link
Copy Markdown
Collaborator

LGTM, thank you

@VikramAditya33 VikramAditya33 merged commit 8d86285 into FOSSFORGE:main May 8, 2026
4 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.

Refactor streaming mode test to use modern async/await pattern

2 participants