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

Fixing flaky tests #3098

Merged
merged 1 commit into from Mar 21, 2024
Merged

Conversation

krmahadevan
Copy link
Member

@krmahadevan krmahadevan commented Mar 21, 2024

Summary by CodeRabbit

  • Tests
    • Adjusted timeout and failure conditions in ElaborateSampleTestCase to improve test reliability.
    • Increased sleep time range in Issue188TestSample to enhance test coverage.
  • Chores
    • Temporarily disabled versionShouldStartWithDigit test in preparation for future updates.

Copy link

coderabbitai bot commented Mar 21, 2024

Walkthrough

The recent updates focus on adjusting timing and test behavior across different components. A test case in ElaborateSampleTestCase.java has been modified to significantly increase its sleep duration and explicitly fail after waking. In another instance, the sleep duration range within Issue188TestSample.java has been expanded to allow for longer sleep times. Additionally, a specific test in PlainOsgiTest.java is temporarily disabled pending a future update, signaling a pause for refinement before its reactivation.

Changes

Files Change Summary
.../issue2916/ElaborateSampleTestCase.java
.../thread/issue188/Issue188TestSample.java
Increased sleep duration and adjusted timing in test methods.
.../test/osgi/PlainOsgiTest.java Disabled specific test pending future updates.

🐇✨
In the realm of code where rabbits dare to tread,
Time stretches and contracts, in tests, it's said.
A pause, a sleep, a wait so long,
Until a fail, or perhaps a future song.
So here we hop, from test to test,
Making each one truly its best.
🌟🐾

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>.
    • Generate unit-tests 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 tests 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@krmahadevan krmahadevan marked this pull request as ready for review March 21, 2024 09:20
@krmahadevan krmahadevan mentioned this pull request Mar 21, 2024
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 69dc232 and 942605c.
Files selected for processing (3)
  • testng-core/src/test/java/test/listeners/issue2916/ElaborateSampleTestCase.java (1 hunks)
  • testng-core/src/test/java/test/thread/issue188/Issue188TestSample.java (1 hunks)
  • testng-test-osgi/src/test/java/org/testng/test/osgi/PlainOsgiTest.java (1 hunks)
Additional comments: 3
testng-core/src/test/java/test/listeners/issue2916/ElaborateSampleTestCase.java (1)
  • 26-29: The modifications to the timingOutTest method, including changing the sleep duration to 10 seconds and adding Assert.fail(), are understood in the context of addressing flaky tests. However, it would be beneficial to add a comment explaining the purpose of the Assert.fail() call, especially for future maintainers or developers who might be examining this test to understand its intended behavior.
testng-core/src/test/java/test/thread/issue188/Issue188TestSample.java (1)
  • 40-40: Increasing the sleep duration in the sleepSilently method introduces variability and may not be the most effective way to address test flakiness related to timing. Consider exploring more deterministic approaches, such as using mock objects or simulating conditions, to achieve consistent test outcomes without relying on actual sleep durations.
testng-test-osgi/src/test/java/org/testng/test/osgi/PlainOsgiTest.java (1)
  • 28-30: Disabling the versionShouldStartWithDigit test with a comment indicating it should be re-enabled after specific conditions are met is a clear and understandable approach. To ensure this test is not forgotten, consider adding a tracking mechanism, such as a TODO with a specific issue number or creating a task in the project's issue tracker, linked to the conditions mentioned in the comment.

@@ -37,7 +37,7 @@ public void anotherSampleTest() {

private void sleepSilently() {
try {
TimeUnit.MILLISECONDS.sleep(500 * random.nextInt(10));
TimeUnit.MILLISECONDS.sleep(5000 * random.nextInt(5));
Copy link
Contributor

Choose a reason for hiding this comment

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

Previously the sleep was "0..5 seconds", and now the timeout is "0..25 seconds". What is the reason for raising the upper bound only?

Copy link
Member Author

Choose a reason for hiding this comment

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

I am just increasing the sleep value so that the sleep happens. I noticed that this test also fails sporadically when the stress parameters are used.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry but I don't understand what is fixed here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Julien - Neither do I to be honest. These failures are very hard for me to reproduce. I am hoping that a bump up in the timeout value may perhaps fix them when running in LCM/GCM mode. Until theres a reliable way to reproduce the issue, I could ONLY do trial and error.

Copy link
Member Author

Choose a reason for hiding this comment

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

Incase you have any ideas on how to reproduce the problem please let me know. Alternatively we can merge this PR and see if it helps.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am just increasing the sleep value so that the sleep happens

@krmahadevan , nextInt can return 0, and in those cases the sleep would be 0.
If you want to increase the sleep here, you should ensure the code does not generate 0 sleeps.

Copy link
Member

Choose a reason for hiding this comment

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

Julien - Neither do I to be honest. These failures are very hard for me to reproduce. I am hoping that a bump up in the timeout value may perhaps fix them when running in LCM/GCM mode. Until theres a reliable way to reproduce the issue, I could ONLY do trial and error.

Why not having both test cases? 2x more probabilities to produce the issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

@juherr I am not sure how that is going to help in reproducing the problem. Having a smaller thread sleep is perhaps not giving enough time for the system to behave as intended when those flags are being passed. I am not sure as to what exactly is getting changed when those flags are being passed. From a functional stand point the code seems to work as re-iterated by the passing test. But under the conditions enforced by LCM/GCM it becomes flaky. Rather than merely throwing more tests and hoping that the issue would show up, I would like to be able to reproduce the problem so that it can be fixed.

@vlsi - Ok. Let me try to fix that by altering the test such that we atleast wait for 5 seconds.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since the intent was to prolong the delay, I chose the path of ensuring that the randomness always returns a non zero value and have pushed the changes. Please check @juherr @vlsi

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 69dc232 and 26a57a2.
Files selected for processing (4)
  • testng-core/src/test/java/test/listeners/issue2916/ElaborateSampleTestCase.java (1 hunks)
  • testng-core/src/test/java/test/thread/issue188/Issue188TestSample.java (1 hunks)
  • testng-core/src/test/java/test/thread/issue188/IssueTest.java (1 hunks)
  • testng-test-osgi/src/test/java/org/testng/test/osgi/PlainOsgiTest.java (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • testng-core/src/test/java/test/listeners/issue2916/ElaborateSampleTestCase.java
  • testng-core/src/test/java/test/thread/issue188/Issue188TestSample.java
  • testng-test-osgi/src/test/java/org/testng/test/osgi/PlainOsgiTest.java
Additional comments: 2
testng-core/src/test/java/test/thread/issue188/IssueTest.java (2)
  • 43-43: The introduction of the permissibleLag variable to control the lag threshold is a good practice as it makes the test more adaptable to different execution environments. However, it's important to document the rationale behind choosing the value of 40 ms for permissibleLag. Understanding the basis for this value can help maintainers adjust it in the future if the test environment changes.
  • 43-56: The logic to check the difference in timestamps to ensure test methods start within the permissible lag is correctly implemented. However, consider adding a comment explaining the significance of this check, especially for future maintainers or contributors who might not be familiar with the context of this flakiness fix. Explaining why a certain lag is acceptable and how it relates to the test's parallel execution could provide valuable insights.

@krmahadevan krmahadevan requested review from juherr and vlsi March 21, 2024 15:32
@krmahadevan krmahadevan merged commit f8d722e into testng-team:master Mar 21, 2024
9 checks passed
@krmahadevan krmahadevan deleted the fix_flaky_tests branch March 21, 2024 17:49
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.

None yet

3 participants