dotCMS / dotCMS/core

Flaky test: KeyValueAPIImplTest.shouldReturnWorkingVersion uses IndexPolicy.FORCE instead of WAIT_FOR

Open Beginner friendly
#35,042 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area : CI/CD Bug Flakey Test stale
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.