* 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
This commit is contained in:
parent
fdc1bdd4d3
commit
e71db0531e
|
@ -39,7 +39,7 @@ public class AsyncTwoPhaseIndexerTests extends ESTestCase {
|
||||||
|
|
||||||
private final CountDownLatch latch;
|
private final CountDownLatch latch;
|
||||||
// test the execution order
|
// test the execution order
|
||||||
private int step;
|
private volatile int step;
|
||||||
|
|
||||||
protected MockIndexer(Executor executor, AtomicReference<IndexerState> initialState, Integer initialPosition,
|
protected MockIndexer(Executor executor, AtomicReference<IndexerState> initialState, Integer initialPosition,
|
||||||
CountDownLatch latch) {
|
CountDownLatch latch) {
|
||||||
|
@ -113,8 +113,8 @@ public class AsyncTwoPhaseIndexerTests extends ESTestCase {
|
||||||
protected void onFinish(ActionListener<Void> listener) {
|
protected void onFinish(ActionListener<Void> listener) {
|
||||||
assertThat(step, equalTo(4));
|
assertThat(step, equalTo(4));
|
||||||
++step;
|
++step;
|
||||||
isFinished.set(true);
|
|
||||||
listener.onResponse(null);
|
listener.onResponse(null);
|
||||||
|
isFinished.set(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -206,8 +206,7 @@ public class AsyncTwoPhaseIndexerTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@AwaitsFix( bugUrl = "https://github.com/elastic/elasticsearch/issues/40946")
|
public void testStateMachine() throws Exception {
|
||||||
public void testStateMachine() throws InterruptedException {
|
|
||||||
AtomicReference<IndexerState> state = new AtomicReference<>(IndexerState.STOPPED);
|
AtomicReference<IndexerState> state = new AtomicReference<>(IndexerState.STOPPED);
|
||||||
final ExecutorService executor = Executors.newFixedThreadPool(1);
|
final ExecutorService executor = Executors.newFixedThreadPool(1);
|
||||||
isFinished.set(false);
|
isFinished.set(false);
|
||||||
|
|
Loading…
Reference in New Issue