Skip to content
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

feat: support parallel tests #287

Merged
merged 8 commits into from
Feb 13, 2025
Merged

feat: support parallel tests #287

merged 8 commits into from
Feb 13, 2025

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Feb 13, 2025

closes #286

Summary by CodeRabbit

  • Chores

    • Enhanced the continuous integration pipeline to run tests in parallel for improved efficiency.
  • New Features

    • Enabled distribution of test files across multiple parallel jobs to optimize the testing process.
    • Introduced a new dependency to facilitate parallel test execution.
  • Tests

    • Added a test case to verify the functionality of running tests in parallel across different CI jobs.
    • Updated test suite for a TypeScript cluster application to improve asynchronous handling and debugging.
    • Implemented conditional checks to skip specific tests based on platform and Node.js version.

Copy link

vercel bot commented Feb 13, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
egg-bin ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 13, 2025 2:37pm

Copy link

coderabbitai bot commented Feb 13, 2025

Warning

Rate limit exceeded

@fengmk2 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 17 minutes and 14 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 3fd6ec9 and 3e12a72.

📒 Files selected for processing (1)
  • test/ts.test.ts (1 hunks)

Walkthrough

This update modifies the continuous integration configuration and test execution logic to enable parallelized testing. The CI workflow now uses a new testing action with a parallelization parameter, and a new dependency is added to support this functionality. Additionally, the test command is updated to split test files based on the current CI job index, and a new test case has been introduced to verify the correct distribution of tests.

Changes

File(s) Change Summary
.github/workflows/nodejs.yml Updated the CI workflow to use node-test-parallel.yml with a new parallel: 2 parameter and modified the version parameter to include only 18, 20, 22.
package.json Added the dependency "ci-parallel-vars": "^1.0.1" to support parallel test configuration; updated esbuild to ^0.25.0 and esbuild-register to ^3.6.0.
src/commands/test.ts Integrated ci-parallel-vars in test command logic to split test files across parallel CI jobs; updated variable declaration from const to let and modified slicing logic to distribute files.
test/commands/test.test.ts Added a new test case to verify the functionality of running tests in parallel across different CI jobs.
test/fixtures/example-ts-cluster/test/index.test.ts Updated the test suite to include asynchronous behavior, added a delay before tests, and modified request handling to properly log and await requests.
test/ts.test.ts Introduced a conditional check to skip tests on Linux with Node.js version 22, adding a comment for clarity.

Sequence Diagram(s)

sequenceDiagram
    participant CI as CI Workflow
    participant Test as Test Command
    participant CP as ciParallelVars
    participant TR as Test Runner

    CI->>Test: Trigger test job with CI_NODE_INDEX & CI_NODE_TOTAL
    Test->>CP: Retrieve parallel variables (index, total)
    CP-->>Test: Return parallel execution details
    Test->>Test: Slice test files based on CI job index
    Test->>TR: Execute selected test files
    TR-->>Test: Return test results
Loading

Poem

I’m hopping through the lines of code today,
Where tests now split in a parallel play.
Each carrot of logic freshly sliced and neat,
Making CI journeys light and sweet.
A rabbit’s cheer for a workflow so fleet!
🐰✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

socket-security bot commented Feb 13, 2025

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/[email protected] None 0 4.27 kB thejameskyle
npm/[email protected] None 0 22.7 MB typescript-bot

View full report↗︎

Copy link

pkg-pr-new bot commented Feb 13, 2025

Open in Stackblitz

npm i https://pkg.pr.new/eggjs/bin/@eggjs/bin@287

commit: 3e12a72

Copy link

@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: 1

🧹 Nitpick comments (1)
src/commands/test.ts (1)

9-10: Consider adding type definitions.

The ts-expect-error comment suggests missing types. Consider creating and contributing type definitions for ci-parallel-vars.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8ec2d70 and aee7ec6.

📒 Files selected for processing (4)
  • .github/workflows/nodejs.yml (1 hunks)
  • package.json (1 hunks)
  • src/commands/test.ts (2 hunks)
  • test/commands/test.test.ts (1 hunks)
🔇 Additional comments (4)
package.json (1)

26-26: LGTM! Good choice of dependency.

The ci-parallel-vars package is a reliable choice for managing test parallelization in CI environments.

.github/workflows/nodejs.yml (1)

12-12: LGTM! Good parallel job configuration.

The changes effectively enable parallel testing:

  • Using node-test-parallel.yml action
  • Setting 4 parallel jobs is a good balance between speed and resource usage

Also applies to: 16-16

src/commands/test.ts (1)

171-171: LGTM! Variable declaration change.

Changing from const to let is necessary for the parallel execution logic.

test/commands/test.test.ts (1)

23-39: LGTM! Comprehensive test coverage.

The test case effectively verifies parallel execution:

  • Tests environment variable handling
  • Validates file splitting logic
  • Checks execution output and success

src/commands/test.ts Show resolved Hide resolved
Copy link

@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: 1

🧹 Nitpick comments (1)
.github/workflows/nodejs.yml (1)

16-17: Consider removing redundant action_ref parameter.

The action_ref parameter appears redundant since the action is already referenced with @test-parallel. This could lead to maintenance issues if the values get out of sync.

     uses: node-modules/github-actions/.github/workflows/node-test-parallel.yml@test-parallel
     with:
       os: 'ubuntu-latest, macos-latest, windows-latest'
       version: '18.19.0, 18, 20, 22, 23'
       parallel: 4
-      action_ref: 'test-parallel'
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aee7ec6 and c25f207.

📒 Files selected for processing (1)
  • .github/workflows/nodejs.yml (1 hunks)

.github/workflows/nodejs.yml Outdated Show resolved Hide resolved
Copy link

codecov bot commented Feb 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.85%. Comparing base (ebfc9c4) to head (3e12a72).
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #287      +/-   ##
==========================================
+ Coverage   95.79%   95.85%   +0.05%     
==========================================
  Files          22       22              
  Lines        1070     1085      +15     
  Branches      170      172       +2     
==========================================
+ Hits         1025     1040      +15     
  Misses         45       45              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@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: 0

🧹 Nitpick comments (2)
test/fixtures/example-ts-cluster/test/index.test.ts (2)

7-16: Consider the impact of debug logging on parallel test performance.

While debug logging can be helpful, it might generate excessive output when running tests in parallel. Consider making it conditional based on a debug flag or environment variable.

-    app.debug();
+    if (process.env.DEBUG) {
+      app.debug();
+    }

Review the necessity of the fixed delay.

The 1-second delay after app.ready() seems arbitrary and could unnecessarily slow down parallel test execution. Consider:

  1. Using app events or health checks instead of a fixed delay
  2. Making the delay configurable
  3. Documenting why this specific delay is needed

Could you explain the rationale behind the 1-second delay? This might help identify a more optimal solution.


20-22: Consider conditional logging for parallel test execution.

While logging the request URL is helpful for debugging, it might generate excessive output when running tests in parallel. Consider making it conditional:

-    console.log('request %s', url);
+    if (process.env.DEBUG) {
+      console.log('request %s', url);
+    }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1944f27 and 8263ed5.

📒 Files selected for processing (2)
  • .github/workflows/nodejs.yml (1 hunks)
  • test/fixtures/example-ts-cluster/test/index.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/nodejs.yml
⏰ Context from checks skipped due to timeout of 90000ms (17)
  • GitHub Check: Node.js / Test (windows-latest, 22, 1:2)
  • GitHub Check: Node.js / Test (windows-latest, 22, 0:2)
  • GitHub Check: Node.js / Test (windows-latest, 20, 1:2)
  • GitHub Check: Node.js / Test (windows-latest, 20, 0:2)
  • GitHub Check: Node.js / Test (windows-latest, 18, 1:2)
  • GitHub Check: Node.js / Test (windows-latest, 18, 0:2)
  • GitHub Check: Node.js / Test (ubuntu-latest, 22, 1:2)
  • GitHub Check: Node.js / Test (ubuntu-latest, 22, 0:2)
  • GitHub Check: Node.js / Test (ubuntu-latest, 20, 1:2)
  • GitHub Check: Node.js / Test (ubuntu-latest, 20, 0:2)
  • GitHub Check: Node.js / Test (ubuntu-latest, 18, 1:2)
  • GitHub Check: Node.js / Test (macos-latest, 20, 1:2)
  • GitHub Check: Node.js / Test (ubuntu-latest, 18, 0:2)
  • GitHub Check: Node.js / Test (macos-latest, 22, 1:2)
  • GitHub Check: Node.js / Test (macos-latest, 18, 0:2)
  • GitHub Check: Node.js / Test (macos-latest, 20, 0:2)
  • GitHub Check: Node.js / Test (macos-latest, 18, 1:2)
🔇 Additional comments (2)
test/fixtures/example-ts-cluster/test/index.test.ts (2)

1-1: LGTM: Appropriate use of built-in Node.js scheduler.

The scheduler import from node:timers/promises is correctly used for implementing the wait functionality.


5-5: LGTM: Improved test identification for parallel execution.

The more explicit test path in the describe block title helps with test identification when running tests in parallel.

Copy link

@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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8263ed5 and 9b9644c.

📒 Files selected for processing (1)
  • test/ts.test.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (17)
  • GitHub Check: Node.js / Test (windows-latest, 22, 1:2)
  • GitHub Check: Node.js / Test (windows-latest, 22, 0:2)
  • GitHub Check: Node.js / Test (windows-latest, 20, 1:2)
  • GitHub Check: Node.js / Test (windows-latest, 18, 0:2)
  • GitHub Check: Node.js / Test (windows-latest, 18, 1:2)
  • GitHub Check: Node.js / Test (ubuntu-latest, 22, 1:2)
  • GitHub Check: Node.js / Test (windows-latest, 20, 0:2)
  • GitHub Check: Node.js / Test (ubuntu-latest, 20, 1:2)
  • GitHub Check: Node.js / Test (ubuntu-latest, 22, 0:2)
  • GitHub Check: Node.js / Test (ubuntu-latest, 20, 0:2)
  • GitHub Check: Node.js / Test (ubuntu-latest, 18, 1:2)
  • GitHub Check: Node.js / Test (ubuntu-latest, 18, 0:2)
  • GitHub Check: Node.js / Test (macos-latest, 22, 0:2)
  • GitHub Check: Node.js / Test (macos-latest, 18, 1:2)
  • GitHub Check: Node.js / Test (macos-latest, 20, 0:2)
  • GitHub Check: Node.js / Test (macos-latest, 18, 0:2)
  • GitHub Check: Node.js / Test (macos-latest, 20, 1:2)

test/ts.test.ts Outdated Show resolved Hide resolved
@fengmk2 fengmk2 merged commit b3f2b6c into master Feb 13, 2025
27 checks passed
@fengmk2 fengmk2 deleted the support-parallel branch February 13, 2025 14:57
fengmk2 pushed a commit that referenced this pull request Feb 13, 2025
[skip ci]

## [7.2.0](v7.1.0...v7.2.0) (2025-02-13)

### Features

* support parallel tests ([#287](#287)) ([b3f2b6c](b3f2b6c))
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.

support splitting tests in CI
1 participant