Fix three flaky tests in TaskQueueTest.java #14896
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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