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

fix: use NX for test parallelism #17652

Merged
merged 6 commits into from
Jan 24, 2025
Merged

fix: use NX for test parallelism #17652

merged 6 commits into from
Jan 24, 2025

Conversation

busla
Copy link
Member

@busla busla commented Jan 24, 2025

Move linux parallelism in unit-tests to NX parallelism

  • Use NX for what it's built for.

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced CI/CD workflow with more granular project-specific testing
    • Added support for running tests across multiple affected projects
  • Improvements

    • Refined test execution strategy with improved flaky test handling
    • Introduced more flexible code coverage configuration
  • Changes

    • Updated GitHub Actions workflow to support project-specific testing
    • Simplified test script execution method
  • Chores

    • Removed legacy parallel execution script
    • Streamlined continuous integration processes

@busla busla requested a review from a team as a code owner January 24, 2025 16:22
Copy link
Contributor

coderabbitai bot commented Jan 24, 2025

Warning

Rate limit exceeded

@busla has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 19 minutes and 27 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 df9304c and d6703e4.

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

Walkthrough

The pull request introduces changes to the CI/CD pipeline, focusing on test execution and project configuration. A new input parameter affected-projects is added to the GitHub Actions workflow, modifying how tests are run. The script 30_test.sh now uses yarn nx run-many to execute tests across multiple projects, replacing the previous approach. The script run-affected-in-parallel.sh has been removed, indicating a consolidation of parallel execution logic.

Changes

File Change Summary
.github/actions/unit-test/action.yml Added required input affected-projects
.github/workflows/push.yml Introduced new environment variable affected-projects
scripts/ci/30_test.sh Modified test execution command to use yarn nx run-many, added functions for flaky tests and code coverage
scripts/ci/run-affected-in-parallel.sh Deleted script for parallel project execution

Possibly related PRs

  • chore: upgrade node version #14968: This PR modifies the .github/actions/unit-test/action.yml, which is directly related to the main PR's changes in the same file, specifically regarding the configuration of the unit test action.
  • ci: increase parallelism #17581: This PR updates the .github/workflows/push.yml, which is also related to the main PR as it introduces new environment variables and modifies the workflow that utilizes the affected-projects variable, enhancing the testing process.

Suggested labels

automerge, test everything

Suggested reviewers

  • brynjarorng
  • AndesKrrrrrrrrrrr
  • magnearun

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.

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
Contributor

@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 (1)
.github/actions/unit-test/action.yml (1)

4-6: Improve the input parameter description.

The description "Generated projects" is too vague. Consider providing more context about what these projects represent and how they are generated.

   affected-projects:
-    description: 'Generated projects'
+    description: 'Comma-separated list of projects affected by changes, generated by NX for parallel test execution'
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fa5f883 and 268479a.

📒 Files selected for processing (4)
  • .github/actions/unit-test/action.yml (3 hunks)
  • .github/workflows/push.yml (1 hunks)
  • scripts/ci/30_test.sh (1 hunks)
  • scripts/ci/run-affected-in-parallel.sh (0 hunks)
💤 Files with no reviewable changes (1)
  • scripts/ci/run-affected-in-parallel.sh
🧰 Additional context used
📓 Path-based instructions (1)
scripts/ci/30_test.sh (1)

Pattern scripts/**/*: "Confirm that the code adheres to the following:

  • Script efficiency, readability, and maintainability.
  • Usage of environmental variables and configuration files for flexibility.
  • Integration with NX workspace utilities and commands."
🔇 Additional comments (3)
scripts/ci/30_test.sh (1)

52-52: LGTM! But verify the variable usage consistency.

The change to use NX's run-many command for test execution is good and aligns with the PR objective. However, the script still uses ${APP} for flaky test detection and code coverage collection while using ${AFFECTED_PROJECTS} for test execution.

Please verify that:

  1. Flaky test detection works correctly with multiple projects
  2. Code coverage collection works as expected with the new parallel execution
  3. The environment variable DD_SERVICE is set correctly for each project

Run this script to check the variable usage:

✅ Verification successful

All variable usages are consistent and working correctly with parallel execution

The script handles all three verification points correctly:

  • Flaky test detection works per-project using the APP variable
  • Code coverage collection and upload are properly configured per-project
  • DD_SERVICE environment variable is correctly set with proper fallbacks
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential issues with variable usage in the test script

# Test 1: Check if APP is still used in other scripts
echo "Checking APP variable usage in other scripts..."
rg -l '\$APP|\$\{APP\}' scripts/

# Test 2: Check if AFFECTED_PROJECTS is consistently used
echo "Checking AFFECTED_PROJECTS variable usage..."
rg -l '\$AFFECTED_PROJECTS|\$\{AFFECTED_PROJECTS\}' scripts/

# Test 3: Check for potential variable conflicts
echo "Checking for potential variable conflicts in CI scripts..."
rg '(APP|AFFECTED_PROJECTS)=' scripts/

Length of output: 1209


Script:

#!/bin/bash
# Check specific usage of APP in test and coverage scripts
echo "Checking APP usage in test script..."
rg -A 5 -B 5 '\$APP|\$\{APP\}' scripts/ci/30_test.sh

echo -e "\nChecking APP usage in coverage script..."
rg -A 5 -B 5 '\$APP|\$\{APP\}' scripts/ci/50_upload-coverage.sh

echo -e "\nChecking DD_SERVICE configuration..."
rg -A 5 -B 5 'DD_SERVICE' scripts/ci/

Length of output: 3191

.github/actions/unit-test/action.yml (1)

33-33: LGTM! Clean migration to NX-based test execution.

The changes correctly wire up the affected projects through environment variables and simplify test execution by leveraging NX's built-in parallelism capabilities.

Also applies to: 48-49

.github/workflows/push.yml (1)

486-486: LGTM! Consistent integration of NX parallel test execution.

The change correctly wires up the affected projects parameter to the unit-test action, completing the integration of NX-based parallel test execution.

Copy link
Contributor

@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 (5)
scripts/ci/30_test.sh (5)

37-46: Consider a more specific function name.

The function correctly implements flaky test detection, but consider renaming it to has_flaky_projects or contains_flaky_projects to better reflect its purpose.

-is_any_project_flaky() {
+has_flaky_projects() {

48-57: Maintain consistency in array comparison logic.

The array comparison could be simplified to match the pattern used in is_any_project_flaky().

-    if [[ ! " ${projects_uncollectible_coverage[*]} " =~ \ ${project}\  ]]; then
+    if [[ " ${projects_uncollectible_coverage[*]} " != *" ${project} "* ]]; then

59-62: Consider a more specific variable name.

Since EXTRA_OPTS is only used for code coverage, consider renaming it to COVERAGE_OPTS for clarity.

-EXTRA_OPTS=""
+COVERAGE_OPTS=""

 if requires_code_coverage; then
-  EXTRA_OPTS="--codeCoverage"
+  COVERAGE_OPTS="--codeCoverage"
 fi

71-78: Enhance error handling in the retry loop.

While the retry logic is solid, consider improving error handling:

  1. Add a descriptive error message when all retries are exhausted
  2. Distinguish between different types of failures (e.g., test failures vs infrastructure issues)
 for ((i = 1; i <= MAX_RETRIES; i++)); do
   echo "Running tests for projects: ${AFFECTED_PROJECTS} (attempt: ${i}/${MAX_RETRIES})"
-  if yarn nx run-many --projects "${AFFECTED_PROJECTS}" --target test ${EXTRA_OPTS} --verbose --no-watchman "$@"; then
+  if ! yarn nx run-many --projects "${AFFECTED_PROJECTS}" --target test ${EXTRA_OPTS} --verbose --no-watchman "$@"; then
+    exit_code=$?
+    if [ $exit_code -eq 1 ]; then
+      echo "Tests failed with exit code ${exit_code}"
+      [ $i -eq $MAX_RETRIES ] && echo "All retry attempts exhausted. Tests failed." && exit 1
+      continue
+    else
+      echo "Infrastructure/setup error (exit code: ${exit_code}). Stopping execution."
+      exit $exit_code
+    fi
+  else
     exit 0
   fi
 done
-
-exit 1

Line range hint 1-78: Well-structured implementation of NX-based parallel testing.

The script successfully implements parallel test execution using NX while maintaining proper handling of flaky tests and code coverage. The implementation is clean, follows bash best practices, and aligns well with the PR objectives.

Consider documenting the following in the repository's documentation:

  1. The purpose and configuration of flaky tests
  2. The criteria for excluding projects from code coverage
  3. The retry strategy and its rationale
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 268479a and a9be7a7.

📒 Files selected for processing (1)
  • scripts/ci/30_test.sh (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
scripts/ci/30_test.sh (1)

Pattern scripts/**/*: "Confirm that the code adheres to the following:

  • Script efficiency, readability, and maintainability.
  • Usage of environmental variables and configuration files for flexibility.
  • Integration with NX workspace utilities and commands."
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: prepare
🔇 Additional comments (2)
scripts/ci/30_test.sh (2)

7-7: LGTM! Simplified environment variable initialization.

The simplified initialization of DD_SERVICE improves clarity while maintaining the correct DataDog service naming.


64-69: LGTM! Clear retry configuration logic.

The retry configuration is well-structured and correctly handles both flaky and non-flaky test scenarios.

Copy link

codecov bot commented Jan 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 35.56%. Comparing base (cb8bfb0) to head (d6703e4).
Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #17652   +/-   ##
=======================================
  Coverage   35.56%   35.56%           
=======================================
  Files        7033     7033           
  Lines      150621   150621           
  Branches    43022    43031    +9     
=======================================
+ Hits        53561    53562    +1     
+ Misses      97060    97059    -1     
Flag Coverage Δ
air-discount-scheme-backend 48.13% <ø> (ø)
air-discount-scheme-web 0.00% <ø> (ø)
api 3.33% <ø> (ø)
api-domains-air-discount-scheme 37.84% <ø> (ø)
api-domains-auth-admin 48.49% <ø> (ø)
api-domains-driving-license 44.74% <ø> (ø)
application-system-api 38.62% <ø> (-0.01%) ⬇️
application-template-api-modules 27.56% <ø> (ø)
application-templates-new-primary-school 20.58% <ø> (ø)
application-ui-shell 21.99% <ø> (ø)
auth-admin-web 2.43% <ø> (ø)
auth-shared 75.00% <ø> (ø)
contentful-apps 4.56% <ø> (ø)
financial-aid-backend 51.35% <ø> (ø)
icelandic-names-registry-backend 54.44% <ø> (ø)
judicial-system-api 20.07% <ø> (ø)
judicial-system-backend 55.79% <ø> (ø)
license-api 42.93% <ø> (+0.07%) ⬆️
services-sessions 65.31% <ø> (+0.04%) ⬆️
services-university-gateway 49.33% <ø> (ø)
services-user-notification 46.51% <ø> (ø)
services-user-profile 56.91% <ø> (ø)
web 2.39% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

see 1 file with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cb8bfb0...d6703e4. Read the comment docs.

@busla busla enabled auto-merge January 24, 2025 16:57
Copy link
Member

@pro-ingvar pro-ingvar left a comment

Choose a reason for hiding this comment

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

Approved, looks good to me.

Copy link
Contributor

@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 (4)
scripts/ci/30_test.sh (4)

37-46: Add documentation for the expected input format.

The function works correctly, but it would be helpful to add a comment explaining that AFFECTED_PROJECTS should be a comma-separated list of project names.

+# Expects AFFECTED_PROJECTS as a comma-separated list of project names
+# Example: "project1,project2,project3"
 is_any_project_flaky() {

48-57: Optimize the function with early return.

The function can be more efficient by returning early when finding the first project that requires code coverage.

 requires_code_coverage() {
   IFS=',' read -ra PROJECTS <<<"$AFFECTED_PROJECTS"
   for project in "${PROJECTS[@]}"; do
     if [[ ! " ${projects_uncollectible_coverage[*]} " =~ \ ${project}\  ]]; then
       return 0
-    fi
-  done
-  return 1
+    fi
+  done
+  return 1
 }

64-69: Consider moving configuration to a separate file.

To improve maintainability and follow the guideline for using configuration files, consider moving FLAKY_TEST_RETRIES and other configuration values to a separate config file.

This would allow easier management of environment-specific settings.


71-78: Enhance error handling and logging.

While the NX integration is well-implemented, consider improving error handling by capturing and logging the error output for better debugging in CI.

 for ((i = 1; i <= MAX_RETRIES; i++)); do
   echo "Running tests for projects: ${AFFECTED_PROJECTS} (attempt: ${i}/${MAX_RETRIES})"
-  if yarn nx run-many --projects "${AFFECTED_PROJECTS}" --target test --parallel="${NX_PARALLEL}" ${EXTRA_OPTS} --verbose --no-watchman "$@"; then
+  if OUTPUT=$(yarn nx run-many --projects "${AFFECTED_PROJECTS}" --target test --parallel="${NX_PARALLEL}" ${EXTRA_OPTS} --verbose --no-watchman "$@" 2>&1); then
     exit 0
+  else
+    echo "Test execution failed with output:"
+    echo "$OUTPUT"
   fi
 done
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a9be7a7 and df9304c.

📒 Files selected for processing (1)
  • scripts/ci/30_test.sh (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
scripts/ci/30_test.sh (1)

Pattern scripts/**/*: "Confirm that the code adheres to the following:

  • Script efficiency, readability, and maintainability.
  • Usage of environmental variables and configuration files for flexibility.
  • Integration with NX workspace utilities and commands."
🔇 Additional comments (2)
scripts/ci/30_test.sh (2)

7-7: LGTM! Simplified environment variable initialization.

The simplified initialization of DD_SERVICE improves readability and removes unnecessary complexity.


59-62: LGTM! Clear and efficient code coverage configuration.

The conditional setting of code coverage options is well-implemented.

@busla busla added this pull request to the merge queue Jan 24, 2025
Merged via the queue into main with commit e596957 Jan 24, 2025
91 of 94 checks passed
@busla busla deleted the remove-test-parallel branch January 24, 2025 19:37
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.

2 participants