Skip to content

Commit 3322df3

Browse files
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 e39c13a commit 3322df3

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
@@ -54,12 +54,14 @@
5454
import java.util.List;
5555
import java.util.Map;
5656
import java.util.concurrent.TimeUnit;
57+
import java.util.stream.StreamSupport;
5758

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

266274
// Now make sure the indexing request finishes successfully
267275
disruption.stopDisrupting();
268-
assertBusy(() -> {
269-
assertTrue(putMappingResponse.get(10, TimeUnit.SECONDS).isAcknowledged());
270-
assertThat(docIndexResponse.get(10, TimeUnit.SECONDS), instanceOf(IndexResponse.class));
271-
assertEquals(1, docIndexResponse.get(10, TimeUnit.SECONDS).getShardInfo().getTotal());
272-
});
276+
assertTrue(putMappingResponse.get(10, TimeUnit.SECONDS).isAcknowledged());
277+
assertThat(docIndexResponse.get(10, TimeUnit.SECONDS), instanceOf(IndexResponse.class));
278+
assertEquals(1, docIndexResponse.get(10, TimeUnit.SECONDS).getShardInfo().getTotal());
273279
}
274280

275281
public void testDelayedMappingPropagationOnReplica() throws Exception {
@@ -370,11 +376,9 @@ public void testDelayedMappingPropagationOnReplica() throws Exception {
370376

371377
// Now make sure the indexing request finishes successfully
372378
disruption.stopDisrupting();
373-
assertBusy(() -> {
374-
assertTrue(putMappingResponse.get(10, TimeUnit.SECONDS).isAcknowledged());
375-
assertThat(docIndexResponse.get(10, TimeUnit.SECONDS), instanceOf(IndexResponse.class));
376-
assertEquals(2, docIndexResponse.get(10, TimeUnit.SECONDS).getShardInfo().getTotal()); // both shards should have succeeded
377-
});
379+
assertTrue(putMappingResponse.get(10, TimeUnit.SECONDS).isAcknowledged());
380+
assertThat(docIndexResponse.get(10, TimeUnit.SECONDS), instanceOf(IndexResponse.class));
381+
assertEquals(2, docIndexResponse.get(10, TimeUnit.SECONDS).getShardInfo().getTotal()); // both shards should have succeeded
378382

379383
assertThat(dynamicMappingsFut.get(10, TimeUnit.SECONDS).getResult(), equalTo(CREATED));
380384
}

0 commit comments

Comments
 (0)