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 flaky test in SearchesCleanUpJobWithDBServicesTest #20740

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

everbrightw
Copy link

Description

I encountered non-deterministic behavior for test:
org.graylog.plugins.views.search.db.SearchesCleanUpJobWithDBServicesTest#testMixedExpiredNonExpiredReferencedAndNonReferencedSearches

Error Message:

[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 4.819 s <<< FAILURE! -- in org.graylog.plugins.views.search.db.SearchesCleanUpJobWithDBServicesTest
[ERROR] org.graylog.plugins.views.search.db.SearchesCleanUpJobWithDBServicesTest.testMixedExpiredNonExpiredReferencedAndNonReferencedSearches -- Time elapsed: 4.795 s <<< FAILURE!
org.opentest4j.AssertionFailedError:

Expecting actual:
  ["5b3b44ca77196aa4679e4da2", "5b3b44ca77196aa4679e4da1"]
to contain exactly (and in same order):
  ["5b3b44ca77196aa4679e4da1", "5b3b44ca77196aa4679e4da2"]
but there were differences at these indexes:
  - element at index 0: expected "5b3b44ca77196aa4679e4da1" but was "5b3b44ca77196aa4679e4da2"
  - element at index 1: expected "5b3b44ca77196aa4679e4da2" but was "5b3b44ca77196aa4679e4da1"

Motivation and Context

The test was previously using containsExactly, which assumes a strict order for the captured values. However, captured value inherently relies on unordered collection HashSet at SearchesCleanUpJob.java#L99 which inherently calls SearchDbService.java#L145.

For this test, to avoid flakiness, I think we can switch to containsExactlyInAnyOrder by checking for the presence of all elements, regardless of their order.

How Has This Been Tested?

I found this non-deterministic behavior by running NonDex.

NonDex:https://github.com/TestingResearchIllinois/NonDex

In short, NonDex is a tool that introduces randomness by deliberately shuffling e.g. unordered collections like HashSet to detect flakiness in code.

You can reproduce the failures/run the tests with NonDex by using the command e.g.:

mvn -pl graylog2-server edu.illinois:nondex-maven-plugin:2.1.7:nondex -Dtest=org.graylog.plugins.views.search.db.SearchesCleanUpJobWithDBServicesTest#testMixedExpiredNonExpiredReferencedAndNonReferencedSearches -DnondexMode=ONE

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

…rder

The test was previously using containsExactly, which assumes a strict order for the captured values. However, captured value inherently relies on unordered collection HashSet, switching to containsExactlyInAnyOrder resolves the flakiness by checking for the presence of all elements, regardless of their order.

Signed-off-by: Yusen Wang <[email protected]>
@CLAassistant
Copy link

CLAassistant commented Oct 20, 2024

CLA assistant check
All committers have signed the CLA.

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