Skip to content

Commit 53d2c47

Browse files
committed
Fix testRunStateChangePolicyWithAsyncActionNextStep race condition (#40707)
Previously we only set the latch countdown with `nextStep.setLatch` after the cluster state change has already been counted down. However, it's possible execution could have already started, causing the latch to be missed when the `MockAsyncActionStep` is being executed. This moves the latch setting to be before the call to `runPolicyAfterStateChange`, which means it is always available when the `MockAsyncActionStep` is executed. I was able to reproduce the failure every 30-40 runs before this change. With this change, running 2000+ times the test passes. Resolves #40018
1 parent 4ed591a commit 53d2c47

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,12 @@ public void testRunStateChangePolicyWithAsyncActionNextStep() throws Exception {
385385
ClusterState before = clusterService.state();
386386
CountDownLatch latch = new CountDownLatch(1);
387387
step.setLatch(latch);
388+
CountDownLatch asyncLatch = new CountDownLatch(1);
389+
nextStep.setLatch(asyncLatch);
388390
runner.runPolicyAfterStateChange(policyName, indexMetaData);
389391

390392
// Wait for the cluster state action step
391393
awaitLatch(latch, 5, TimeUnit.SECONDS);
392-
393-
CountDownLatch asyncLatch = new CountDownLatch(1);
394-
nextStep.setLatch(asyncLatch);
395-
396394
// Wait for the async action step
397395
awaitLatch(asyncLatch, 5, TimeUnit.SECONDS);
398396
ClusterState after = clusterService.state();

0 commit comments

Comments
 (0)