Flaky test: KeyValueAPIImplTest.shouldReturnWorkingVersion uses IndexPolicy.FORCE instead of WAIT_FOR
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 970
- Forks
- 486
- Avg merge
- 3d 33m
- Merged PRs (30d)
- 170
Description
Summary
KeyValueAPIImplTest.shouldReturnWorkingVersion intermittently fails with:
org.junit.ComparisonFailure: expected:<test[ 2]> but was:<test[]>
Root Cause
ContentUtils.updateTestKeyValueContent() sets IndexPolicy.FORCE (line 127), which triggers immediate ES indexing but does not block until the document is searchable. The test then queries ES via KeyValueAPIImpl.get() with +working:true. Most of the time FORCE is fast enough, but occasionally the query runs before ES has made the updated document searchable, returning the old value "test" instead of "test 2".
The Thread.sleep(1000) at line 83 of the test is a bandaid for this race but isn't sufficient under load.
File: dotcms-integration/src/test/java/com/dotcms/keyvalue/busines/KeyValueAPIImplTest.java:70
Fix
Change IndexPolicy.FORCE to IndexPolicy.WAIT_FOR in the test setup (updateTestKeyValueContent or directly in the test), which blocks until ES confirms searchability. This is the established pattern for test code that doesn't need to test async indexing behavior. The Thread.sleep(1000) can also be removed once WAIT_FOR is in place.
Seen In
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in dotcms-integration/src/test/java/com/dotcms/integrationtestutil/content/ContentUtils.java at line 127 and KeyValueAPIImplTest.java around line 70. Run KeyValueAPIImplTest.shouldReturnWorkingVersion, change the test setup to use WAIT_FOR, and remove the Thread.sleep(1000) workaround. Done means the test reliably returns "test 2" under load.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100