Skip to content

Commit cadb304

Browse files
authored
[ML] Fix DatafeedJobsIT#testDatafeedTimingStats_DatafeedRecreated (elastic#137086) (elastic#137105)
Problem: The test was failing intermittently with AssertionError: Expected: a value greater than <0L> but: <0L> was equal to <0L> due to a race condition between data processing completion and asynchronous datafeed timing stats persistence. Root Cause: Datafeed timing stats are persisted asynchronously. The test's single assertBusy() block checked both data processing completion AND timing stats simultaneously. Data processing could complete before timing stats persistence finished, causing search_count to still appear as 0. Solution: Split the assertion into two phases: Phase 1: Wait for data processing to complete (processedRecordCount == numDocs) Phase 2: Wait for timing stats to be persisted (search_count > 0) This eliminates the race condition while maintaining the test's validation goals and testing realistic client-observable behavior.
1 parent 23edb84 commit cadb304

File tree

1 file changed

+11
-8
lines changed
  • x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration

1 file changed

+11
-8
lines changed

x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/DatafeedJobsIT.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package org.elasticsearch.xpack.ml.integration;
88

99
import org.apache.logging.log4j.Level;
10-
import org.apache.lucene.tests.util.LuceneTestCase;
1110
import org.elasticsearch.ElasticsearchException;
1211
import org.elasticsearch.ElasticsearchStatusException;
1312
import org.elasticsearch.ResourceNotFoundException;
@@ -232,7 +231,6 @@ public void testLookbackOnlyRuntimeMapping() throws Exception {
232231
waitUntilJobIsClosed(jobBuilder.getId());
233232
}
234233

235-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/63973")
236234
public void testDatafeedTimingStats_DatafeedRecreated() throws Exception {
237235
client().admin().indices().prepareCreate("data").setMapping("time", "type=date").get();
238236
long numDocs = randomIntBetween(32, 2048);
@@ -254,11 +252,17 @@ public void testDatafeedTimingStats_DatafeedRecreated() throws Exception {
254252
// Datafeed did not do anything yet, hence search_count is equal to 0.
255253
assertDatafeedStats(datafeedId, DatafeedState.STOPPED, job.getId(), equalTo(0L));
256254
startDatafeed(datafeedId, 0L, now.toEpochMilli());
257-
assertBusy(() -> {
258-
assertThat(getDataCounts(job.getId()).getProcessedRecordCount(), equalTo(numDocs));
259-
// Datafeed processed numDocs documents so search_count must be greater than 0.
260-
assertDatafeedStats(datafeedId, DatafeedState.STOPPED, job.getId(), greaterThan(0L));
261-
}, 60, TimeUnit.SECONDS);
255+
256+
// First, wait for data processing to complete
257+
assertBusy(() -> { assertThat(getDataCounts(job.getId()).getProcessedRecordCount(), equalTo(numDocs)); }, 60, TimeUnit.SECONDS);
258+
// Then, wait for datafeed timing stats to be persisted
259+
// Datafeed processed numDocs documents so search_count must be greater than 0.
260+
assertBusy(
261+
() -> { assertDatafeedStats(datafeedId, DatafeedState.STOPPED, job.getId(), greaterThan(0L)); },
262+
30,
263+
TimeUnit.SECONDS
264+
);
265+
262266
deleteDatafeed(datafeedId);
263267
waitUntilJobIsClosed(job.getId());
264268
};
@@ -788,7 +792,6 @@ private void startRealtime(String jobId, Integer maxEmptySearches) throws Except
788792
}, 30, TimeUnit.SECONDS);
789793
}
790794

791-
@LuceneTestCase.AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/105239")
792795
public void testStartDatafeed_GivenTimeout_Returns408() throws Exception {
793796
client().admin().indices().prepareCreate("data-1").setMapping("time", "type=date").get();
794797
long numDocs = 100;

0 commit comments

Comments
 (0)