Skip to content

Commit

Permalink
Fix testRunStateChangePolicyWithAsyncActionNextStep race condition (e…
Browse files Browse the repository at this point in the history
…lastic#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 elastic#40018
  • Loading branch information
dakrone authored and Gurkan Kaymak committed May 27, 2019
1 parent c814102 commit 34a99f6
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -385,14 +385,12 @@ public void testRunStateChangePolicyWithAsyncActionNextStep() throws Exception {
ClusterState before = clusterService.state();
CountDownLatch latch = new CountDownLatch(1);
step.setLatch(latch);
CountDownLatch asyncLatch = new CountDownLatch(1);
nextStep.setLatch(asyncLatch);
runner.runPolicyAfterStateChange(policyName, indexMetaData);

// Wait for the cluster state action step
awaitLatch(latch, 5, TimeUnit.SECONDS);

CountDownLatch asyncLatch = new CountDownLatch(1);
nextStep.setLatch(asyncLatch);

// Wait for the async action step
awaitLatch(asyncLatch, 5, TimeUnit.SECONDS);
ClusterState after = clusterService.state();
Expand Down

0 comments on commit 34a99f6

Please sign in to comment.