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

Streamline working of shared thread pools #3207

Merged
merged 1 commit into from
Feb 19, 2025

Conversation

krmahadevan
Copy link
Member

@krmahadevan krmahadevan commented Feb 19, 2025

If a user is not using priority driven tests then
TestNG should not consider any method interceptors that a user may be using.

Closes #3179

Fixes #3179 .

Did you remember to?

  • Add test case(s)
  • Update CHANGES.txt
  • Auto applied styling via ./gradlew autostyleApply

We encourage pull requests that:

  • Add new features to TestNG (or)
  • Fix bugs in TestNG

If your pull request involves fixing SonarQube issues then we would suggest that you please discuss this with the
TestNG-dev before you spend time working on it.

Note: For more information on contribution guidelines please make sure you refer our Contributing section for detailed set of steps.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed a ClassCastException when using the shouldUseGlobalThreadPool(true) property.
    • Improved error reporting for test timeouts by ensuring stack traces are propagated correctly.
  • Refactor

    • Enhanced the internal test execution ordering mechanism to better handle prioritization.
  • Tests

    • Added new tests to verify that priority-agnostic interceptors do not cause exceptions.
    • Introduced a sample test suite demonstrating parallel, data-driven test execution.

@krmahadevan krmahadevan requested a review from juherr as a code owner February 19, 2025 03:41
@krmahadevan krmahadevan requested review from juherr and removed request for juherr February 19, 2025 03:42
Copy link

coderabbitai bot commented Feb 19, 2025

Walkthrough

This pull request updates TestNG’s release notes and core functionality. In the release notes (CHANGES.txt), a new fix for GITHUB-3179 is added, and the fix for GITHUB-2765 is updated with contributor attribution. The TestRunner class in the core module modifies the sortOnPriority method, replacing it with boolean flags to determine priority sorting. Additionally, new test classes and methods are introduced in the test suite, including a test for priority-agnostic interceptors, along with new interceptor and listener implementations.

Changes

File(s) Change Summary
CHANGES.txt Updated release notes: added new fix for GITHUB-3179 and updated fix for GITHUB-2765 with contributor attribution.
.../TestRunner.java Removed sortOnPriority method; replaced with boolean flags for determining priority sorting. Updated privateRun method to use new flags.
.../SharedThreadPoolTest.java Added ensurePriorityAgnosticInterceptorsDontCauseExceptions() to validate that priority-agnostic interceptors do not throw exceptions.
.../test/thread/issue3179/{DummyMethodInterceptor, SampleSuiteAlteringListener, TestClassSample}.java Introduced new classes: a dummy method interceptor, a suite altering listener to configure the thread pool, and a sample test class with data provider and multiple test methods.

Possibly related PRs

Suggested reviewers

  • juherr

Poem

Oh, what a hop, a skip, a bound,
I’ve scurried through changes all around!
From sorting tweaks to tests so bright,
Interceptors dancing in delight 🐰.
With fixes and tests now shining through,
This rabbit cheers for code that’s true!
Happy coding, let’s all renew!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a74ee64 and c582ac0.

📒 Files selected for processing (6)
  • CHANGES.txt (1 hunks)
  • testng-core/src/main/java/org/testng/TestRunner.java (1 hunks)
  • testng-core/src/test/java/test/thread/SharedThreadPoolTest.java (2 hunks)
  • testng-core/src/test/java/test/thread/issue3179/DummyMethodInterceptor.java (1 hunks)
  • testng-core/src/test/java/test/thread/issue3179/SampleSuiteAlteringListener.java (1 hunks)
  • testng-core/src/test/java/test/thread/issue3179/TestClassSample.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • testng-core/src/test/java/test/thread/issue3179/DummyMethodInterceptor.java
  • testng-core/src/test/java/test/thread/issue3179/SampleSuiteAlteringListener.java
  • testng-core/src/main/java/org/testng/TestRunner.java
  • testng-core/src/test/java/test/thread/SharedThreadPoolTest.java
  • CHANGES.txt
  • testng-core/src/test/java/test/thread/issue3179/TestClassSample.java
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: 21, zulu, ubuntu, Pacific/Chatham, ru_RU
  • GitHub Check: 21, corretto, macos, UTC, fr_FR, stress JIT
  • GitHub Check: 17, zulu, ubuntu, Pacific/Chatham, tr_TR
  • GitHub Check: 17, microsoft, same hashcode, macos, America/New_York, tr_TR, stress JIT
  • GitHub Check: 17, liberica, macos, Pacific/Chatham, fr_FR, stress JIT
  • GitHub Check: 11, corretto, windows, Pacific/Chatham, fr_FR, stress JIT

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

@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)
testng-core/src/test/java/test/thread/issue3179/SampleSuiteAlteringListener.java (1)

9-13: Consider adding null check and bounds check.

The implementation looks good, but consider adding defensive checks for the suites list to handle edge cases gracefully.

  @Override
  public void alter(List<XmlSuite> suites) {
+   if (suites == null || suites.isEmpty()) {
+     return;
+   }
    suites.get(0).shouldUseGlobalThreadPool(true);
    suites.get(0).setThreadCount(3);
    suites.get(0).setParallel(XmlSuite.ParallelMode.METHODS);
  }
testng-core/src/main/java/org/testng/TestRunner.java (1)

715-717: Verify variable naming for clarity.

Consider renaming variables to better reflect their purpose:

  • determined.first() indicates multiple interceptors
  • determined.second() indicates priority differences
- Pair<Boolean, Boolean> determined = sortOnPriority(interceptedOrder);
- boolean needPrioritySort = determined.first() || determined.second();
+ Pair<Boolean, Boolean> sortingCriteria = sortOnPriority(interceptedOrder);
+ boolean hasMultipleInterceptorsOrPriorities = sortingCriteria.first() || sortingCriteria.second();

Also applies to: 727-727

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f0e7391 and a74ee64.

📒 Files selected for processing (6)
  • CHANGES.txt (1 hunks)
  • testng-core/src/main/java/org/testng/TestRunner.java (3 hunks)
  • testng-core/src/test/java/test/thread/SharedThreadPoolTest.java (2 hunks)
  • testng-core/src/test/java/test/thread/issue3179/DummyMethodInterceptor.java (1 hunks)
  • testng-core/src/test/java/test/thread/issue3179/SampleSuiteAlteringListener.java (1 hunks)
  • testng-core/src/test/java/test/thread/issue3179/TestClassSample.java (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • testng-core/src/test/java/test/thread/issue3179/DummyMethodInterceptor.java
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: 21, liberica, macos, America/New_York, tr_TR, stress JIT
  • GitHub Check: 17, temurin, ubuntu, America/New_York, tr_TR, stress JIT
  • GitHub Check: 17, microsoft, same hashcode, ubuntu, Pacific/Chatham, de_DE
  • GitHub Check: 11, temurin, windows, UTC, ru_RU
  • GitHub Check: 11, temurin, macos, America/New_York, ru_RU, stress JIT
🔇 Additional comments (4)
testng-core/src/test/java/test/thread/issue3179/TestClassSample.java (1)

7-23: LGTM! Well-structured test class.

The test class effectively combines data-driven and regular tests to verify thread pool behavior. The parallel data provider is correctly configured.

testng-core/src/test/java/test/thread/SharedThreadPoolTest.java (1)

88-95: LGTM! Well-implemented test case.

The test method effectively verifies that priority-agnostic interceptors don't cause exceptions. Good use of the new listener and test class.

testng-core/src/main/java/org/testng/TestRunner.java (1)

666-670: LGTM! Improved priority sorting logic.

The method now clearly separates two concerns:

  1. Whether multiple interceptors are present
  2. Whether any method has a non-zero priority

This separation makes the code more maintainable and easier to understand.

CHANGES.txt (1)

2-3: Clear and Concise Release Note Updates

The new release note entries for GITHUB-3179 and GITHUB-2765 succinctly document the fixes and correctly attribute contribution to Krishnan Mahadevan and Charlie Hayes respectively. In particular, the GITHUB-3179 entry addresses the ClassCastException related to the use of the shouldUseGlobalThreadPool(true) property, which ties directly into the PR’s objective of streamlining the shared thread pool functionality in TestNG. Please verify that these descriptions fully capture the behavioral improvements—especially ensuring that the framework now bypasses method interceptors when priority-driven tests are not in use. Overall, the update is clear and correctly formatted.

If a user is not using priority driven tests then
TestNG should not consider any method interceptors
that a user may be using.

Closes testng-team#3179
@krmahadevan krmahadevan merged commit df04c65 into testng-team:master Feb 19, 2025
5 of 10 checks passed
@krmahadevan krmahadevan deleted the fix_issue3179 branch February 19, 2025 09:14
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.

ClassCastException when use shouldUseGlobalThreadPool(true) property
2 participants