Fix RareClusterStateIT Cancelling Publication too Early (#51429) (#51434)

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
This commit is contained in:
Armin Braun 2020-01-24 20:33:45 +01:00 committed by GitHub
parent af1ff52e70
commit ef94a5863a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 11 deletions

View File

@ -55,12 +55,14 @@ import org.elasticsearch.transport.TransportSettings;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.StreamSupport;
import static java.util.Collections.emptyMap; import static java.util.Collections.emptyMap;
import static java.util.Collections.emptySet; import static java.util.Collections.emptySet;
import static org.elasticsearch.action.DocWriteResponse.Result.CREATED; import static org.elasticsearch.action.DocWriteResponse.Result.CREATED;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.hamcrest.Matchers.arrayWithSize;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.hasSize;
@ -142,7 +144,13 @@ public class RareClusterStateIT extends ESIntegTestCase {
// Wait for no publication in progress to not accidentally cancel a publication different from the one triggered by the given // Wait for no publication in progress to not accidentally cancel a publication different from the one triggered by the given
// request. // request.
assertBusy( assertBusy(
() -> assertFalse(((Coordinator) internalCluster().getCurrentMasterNodeInstance(Discovery.class)).publicationInProgress())); () -> {
assertFalse(((Coordinator) internalCluster().getCurrentMasterNodeInstance(Discovery.class)).publicationInProgress());
assertThat(StreamSupport.stream(
internalCluster().getInstances(Discovery.class).spliterator(), false)
.map(coordinator -> ((Coordinator) coordinator).getLastAcceptedState().version())
.distinct().toArray(), arrayWithSize(1));
});
ActionFuture<Res> future = req.execute(); ActionFuture<Res> future = req.execute();
assertBusy( assertBusy(
() -> assertTrue(((Coordinator)internalCluster().getCurrentMasterNodeInstance(Discovery.class)).cancelCommittedPublication())); () -> assertTrue(((Coordinator)internalCluster().getCurrentMasterNodeInstance(Discovery.class)).cancelCommittedPublication()));
@ -268,11 +276,9 @@ public class RareClusterStateIT extends ESIntegTestCase {
// Now make sure the indexing request finishes successfully // Now make sure the indexing request finishes successfully
disruption.stopDisrupting(); disruption.stopDisrupting();
assertBusy(() -> { assertTrue(putMappingResponse.get(10, TimeUnit.SECONDS).isAcknowledged());
assertTrue(putMappingResponse.get(10, TimeUnit.SECONDS).isAcknowledged()); assertThat(docIndexResponse.get(10, TimeUnit.SECONDS), instanceOf(IndexResponse.class));
assertThat(docIndexResponse.get(10, TimeUnit.SECONDS), instanceOf(IndexResponse.class)); assertEquals(1, docIndexResponse.get(10, TimeUnit.SECONDS).getShardInfo().getTotal());
assertEquals(1, docIndexResponse.get(10, TimeUnit.SECONDS).getShardInfo().getTotal());
});
} }
public void testDelayedMappingPropagationOnReplica() throws Exception { public void testDelayedMappingPropagationOnReplica() throws Exception {
@ -373,11 +379,9 @@ public class RareClusterStateIT extends ESIntegTestCase {
// Now make sure the indexing request finishes successfully // Now make sure the indexing request finishes successfully
disruption.stopDisrupting(); disruption.stopDisrupting();
assertBusy(() -> { assertTrue(putMappingResponse.get(10, TimeUnit.SECONDS).isAcknowledged());
assertTrue(putMappingResponse.get(10, TimeUnit.SECONDS).isAcknowledged()); assertThat(docIndexResponse.get(10, TimeUnit.SECONDS), instanceOf(IndexResponse.class));
assertThat(docIndexResponse.get(10, TimeUnit.SECONDS), instanceOf(IndexResponse.class)); assertEquals(2, docIndexResponse.get(10, TimeUnit.SECONDS).getShardInfo().getTotal()); // both shards should have succeeded
assertEquals(2, docIndexResponse.get(10, TimeUnit.SECONDS).getShardInfo().getTotal()); // both shards should have succeeded
});
assertThat(dynamicMappingsFut.get(10, TimeUnit.SECONDS).getResult(), equalTo(CREATED)); assertThat(dynamicMappingsFut.get(10, TimeUnit.SECONDS).getResult(), equalTo(CREATED));
} }