Skip to content

Commit 3493f3b

Browse files
author
Hendrik Muhs
committed
move latch await to doNextSearch (#42275)
move latch await to doNextSearch, fixes a race condition when the executor thread is faster than the coordinator thread fixes #42084
1 parent 34dda75 commit 3493f3b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexing/AsyncTwoPhaseIndexerTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected String getJobId() {
6464

6565
@Override
6666
protected IterationResult<Integer> doProcess(SearchResponse searchResponse) {
67-
awaitForLatch();
67+
assertFalse("should not be called as stoppedBeforeFinished is false", stoppedBeforeFinished);
6868
assertThat(step, equalTo(3));
6969
++step;
7070
return new IterationResult<>(Collections.emptyList(), 3, true);
@@ -99,6 +99,9 @@ protected void doNextSearch(SearchRequest request, ActionListener<SearchResponse
9999
final SearchResponseSections sections = new SearchResponseSections(
100100
new SearchHits(new SearchHit[0], new TotalHits(0, TotalHits.Relation.EQUAL_TO), 0), null,
101101
null, false, null, null, 1);
102+
103+
// block till latch has been counted down, simulating network latency
104+
awaitForLatch();
102105
nextPhase.onResponse(new SearchResponse(sections, null, 1, 1, 0, 0, ShardSearchFailure.EMPTY_ARRAY, null));
103106
}
104107

@@ -222,7 +225,6 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
222225
}
223226
}
224227

225-
@AwaitsFix( bugUrl = "https://github.com/elastic/elasticsearch/issues/42084")
226228
public void testStateMachine() throws Exception {
227229
AtomicReference<IndexerState> state = new AtomicReference<>(IndexerState.STOPPED);
228230
final ExecutorService executor = Executors.newFixedThreadPool(1);
@@ -265,7 +267,6 @@ public void testStateMachineBrokenSearch() throws InterruptedException {
265267
}
266268
}
267269

268-
@AwaitsFix( bugUrl = "https://github.com/elastic/elasticsearch/issues/42084")
269270
public void testStop_AfterIndexerIsFinished() throws InterruptedException {
270271
AtomicReference<IndexerState> state = new AtomicReference<>(IndexerState.STOPPED);
271272
final ExecutorService executor = Executors.newFixedThreadPool(1);
@@ -285,7 +286,6 @@ public void testStop_AfterIndexerIsFinished() throws InterruptedException {
285286
}
286287
}
287288

288-
@AwaitsFix( bugUrl = "https://github.com/elastic/elasticsearch/issues/42084")
289289
public void testStop_WhileIndexing() throws InterruptedException {
290290
AtomicReference<IndexerState> state = new AtomicReference<>(IndexerState.STOPPED);
291291
final ExecutorService executor = Executors.newFixedThreadPool(1);

0 commit comments

Comments
 (0)