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 three flaky tests in TaskQueueTest.java #14896

Open
wants to merge 3 commits into
base: 3.3
Choose a base branch
from

Conversation

ljmcr
Copy link

@ljmcr ljmcr commented Nov 14, 2024

What is the purpose of the change?

Three tests under module dubbo-common are detected as Order-Dependent flaky tests:
dubbo-common\src\test\java\org\apache\dubbo\common\threadpool\support\eager\TaskQueueTest.java#testOffer2
dubbo-common\src\test\java\org\apache\dubbo\common\threadpool\support\eager\TaskQueueTest.java#testOffer3
dubbo-common\src\test\java\org\apache\dubbo\common\threadpool\support\eager\TaskQueueTest.java#testOffer4
There exists circumstances which if queue or executor retain modifications from a previous test (e.g., adding elements or changing state), subsequent tests may inherit an altered state. Tests like testOffer3 and testOffer4 manipulate executor properties such as pool size and active count. If they run in an order where a test expecting an empty state follows one that fills or modifies the queue, the test could fail or produce flaky results.
This approach modify TaskQueueTest class by defining queue and executor as class-level variables and initializing them in the @beforeeach method to ensure each test starts with a fresh and consistent state. This approach prevents potential state contamination between tests, promoting better test isolation and reliability, also ensures that all tests share a consistent setup foundation.

Checklist

  • Make sure there is a GitHub_issue field for the change.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction. If the new feature or significant change is committed, please remember to add sample in dubbo samples project.
  • Make sure gitHub actions can pass. Why the workflow is failing and how to fix it?

fix flaky test

fix flaky test

fix format issue

fix flaky test
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.

1 participant