Skip to content

Commit 00a44b0

Browse files
Fix Race in AsyncTwoPhaseIndexerTests.testStateMachine (#40947)
* The step is incremented by the listner in `org.elasticsearch.xpack.core.indexing.AsyncTwoPhaseIndexerTests.MockIndexer#onFinish` after isFinished is set to true, but the test only waited for `isFinished`, fixed by calling `isFinished` last * Also made `step` volatile since we are reading it from different thread from the one incrementing it * Closes #40946
1 parent 6e4defd commit 00a44b0

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ private class MockIndexer extends AsyncTwoPhaseIndexer<Integer, MockJobStats> {
3939

4040
private final CountDownLatch latch;
4141
// test the execution order
42-
private int step;
42+
private volatile int step;
4343

4444
protected MockIndexer(Executor executor, AtomicReference<IndexerState> initialState, Integer initialPosition,
4545
CountDownLatch latch) {
@@ -113,8 +113,8 @@ protected void onFailure(Exception exc) {
113113
protected void onFinish(ActionListener<Void> listener) {
114114
assertThat(step, equalTo(4));
115115
++step;
116-
isFinished.set(true);
117116
listener.onResponse(null);
117+
isFinished.set(true);
118118
}
119119

120120
@Override
@@ -206,8 +206,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
206206
}
207207
}
208208

209-
@AwaitsFix( bugUrl = "https://github.com/elastic/elasticsearch/issues/40946")
210-
public void testStateMachine() throws InterruptedException {
209+
public void testStateMachine() throws Exception {
211210
AtomicReference<IndexerState> state = new AtomicReference<>(IndexerState.STOPPED);
212211
final ExecutorService executor = Executors.newFixedThreadPool(1);
213212
isFinished.set(false);

0 commit comments

Comments
 (0)