Skip to content

Commit 6ff02bd

Browse files
original-brownbearrjernst
authored andcommitted
Fix RareClusterStateIT Cancelling Publication too Early (#51429)
Wait for the cluster to have settled down and have the same accepted version on all nodes before executing and cancelling request so that a slow CS accept on one node doesn't make it fall behind and then get sent the full CS because of the diff-version mismatch, breaking the mechanics of this test. Closes #51308
1 parent a23b497 commit 6ff02bd

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

server/src/test/java/org/elasticsearch/cluster/coordination/RareClusterStateIT.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@
5555
import java.util.List;
5656
import java.util.Map;
5757
import java.util.concurrent.TimeUnit;
58+
import java.util.stream.StreamSupport;
5859

5960
import static java.util.Collections.emptyMap;
6061
import static java.util.Collections.emptySet;
6162
import static org.elasticsearch.action.DocWriteResponse.Result.CREATED;
6263
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
6364
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
65+
import static org.hamcrest.Matchers.arrayWithSize;
6466
import static org.hamcrest.Matchers.equalTo;
6567
import static org.hamcrest.Matchers.hasItem;
6668
import static org.hamcrest.Matchers.hasSize;
@@ -142,7 +144,13 @@ private <Req extends ActionRequest, Res extends ActionResponse> ActionFuture<Res
142144
// Wait for no publication in progress to not accidentally cancel a publication different from the one triggered by the given
143145
// request.
144146
assertBusy(
145-
() -> assertFalse(((Coordinator) internalCluster().getCurrentMasterNodeInstance(Discovery.class)).publicationInProgress()));
147+
() -> {
148+
assertFalse(((Coordinator) internalCluster().getCurrentMasterNodeInstance(Discovery.class)).publicationInProgress());
149+
assertThat(StreamSupport.stream(
150+
internalCluster().getInstances(Discovery.class).spliterator(), false)
151+
.map(coordinator -> ((Coordinator) coordinator).getLastAcceptedState().version())
152+
.distinct().toArray(), arrayWithSize(1));
153+
});
146154
ActionFuture<Res> future = req.execute();
147155
assertBusy(
148156
() -> assertTrue(((Coordinator)internalCluster().getCurrentMasterNodeInstance(Discovery.class)).cancelCommittedPublication()));
@@ -268,11 +276,9 @@ public void testDelayedMappingPropagationOnPrimary() throws Exception {
268276

269277
// Now make sure the indexing request finishes successfully
270278
disruption.stopDisrupting();
271-
assertBusy(() -> {
272-
assertTrue(putMappingResponse.get(10, TimeUnit.SECONDS).isAcknowledged());
273-
assertThat(docIndexResponse.get(10, TimeUnit.SECONDS), instanceOf(IndexResponse.class));
274-
assertEquals(1, docIndexResponse.get(10, TimeUnit.SECONDS).getShardInfo().getTotal());
275-
});
279+
assertTrue(putMappingResponse.get(10, TimeUnit.SECONDS).isAcknowledged());
280+
assertThat(docIndexResponse.get(10, TimeUnit.SECONDS), instanceOf(IndexResponse.class));
281+
assertEquals(1, docIndexResponse.get(10, TimeUnit.SECONDS).getShardInfo().getTotal());
276282
}
277283

278284
public void testDelayedMappingPropagationOnReplica() throws Exception {
@@ -373,11 +379,9 @@ public void testDelayedMappingPropagationOnReplica() throws Exception {
373379

374380
// Now make sure the indexing request finishes successfully
375381
disruption.stopDisrupting();
376-
assertBusy(() -> {
377-
assertTrue(putMappingResponse.get(10, TimeUnit.SECONDS).isAcknowledged());
378-
assertThat(docIndexResponse.get(10, TimeUnit.SECONDS), instanceOf(IndexResponse.class));
379-
assertEquals(2, docIndexResponse.get(10, TimeUnit.SECONDS).getShardInfo().getTotal()); // both shards should have succeeded
380-
});
382+
assertTrue(putMappingResponse.get(10, TimeUnit.SECONDS).isAcknowledged());
383+
assertThat(docIndexResponse.get(10, TimeUnit.SECONDS), instanceOf(IndexResponse.class));
384+
assertEquals(2, docIndexResponse.get(10, TimeUnit.SECONDS).getShardInfo().getTotal()); // both shards should have succeeded
381385

382386
assertThat(dynamicMappingsFut.get(10, TimeUnit.SECONDS).getResult(), equalTo(CREATED));
383387
}

0 commit comments

Comments
 (0)