From aa14bb1f167220cfb517087bd1cee3be75264949 Mon Sep 17 00:00:00 2001 From: David Turner Date: Thu, 9 Sep 2021 12:32:56 +0100 Subject: [PATCH] Better assertions (and longer run) in testSingleNodeDiscoveryStabilisesEvenWhenDisrupted --- .../cluster/coordination/CoordinatorTests.java | 16 ++++++++++++---- .../AbstractCoordinatorTestCase.java | 6 +++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java b/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java index c74195eec5cef..7e0bf68be8832 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java @@ -1558,22 +1558,30 @@ public void testSingleNodeDiscoveryStabilisesEvenWhenDisrupted() { final long delayVariabilityMillis = randomLongBetween(DEFAULT_DELAY_VARIABILITY, TimeValue.timeValueMinutes(10).millis()); if (randomBoolean()) { cluster.runRandomly(true, false, delayVariabilityMillis); - } else { - cluster.deterministicTaskQueue.setExecutionDelayVariabilityMillis(delayVariabilityMillis); } + cluster.deterministicTaskQueue.setExecutionDelayVariabilityMillis(delayVariabilityMillis); + final ClusterNode clusterNode = cluster.getAnyNode(); + final long clusterStateUpdateDelay = 7 * delayVariabilityMillis; // see definition of DEFAULT_CLUSTER_STATE_UPDATE_DELAY + // cf. DEFAULT_STABILISATION_TIME, but stabilisation is quicker when there's a single node - there's no meaningful fault // detection and ongoing publications do not time out cluster.runFor(ELECTION_INITIAL_TIMEOUT_SETTING.get(Settings.EMPTY).millis() + delayVariabilityMillis // two round trips for pre-voting and voting + 4 * delayVariabilityMillis - // see definition of DEFAULT_CLUSTER_STATE_UPDATE_DELAY - + 7 * delayVariabilityMillis, "stabilising"); + // and then the election update + + clusterStateUpdateDelay, "stabilising"); assertThat(cluster.getAnyLeader(), sameInstance(clusterNode)); + final int pendingTaskCount = clusterNode.getPendingTaskCount(); + cluster.runFor((pendingTaskCount + 1) * clusterStateUpdateDelay, "draining task queue"); + + assertFalse(clusterNode.coordinator.publicationInProgress()); + assertThat(clusterNode.coordinator.getLastAcceptedState().version(), + equalTo(clusterNode.getLastAppliedClusterState().version())); cluster.deterministicTaskQueue.setExecutionDelayVariabilityMillis(DEFAULT_DELAY_VARIABILITY); } } diff --git a/test/framework/src/main/java/org/elasticsearch/cluster/coordination/AbstractCoordinatorTestCase.java b/test/framework/src/main/java/org/elasticsearch/cluster/coordination/AbstractCoordinatorTestCase.java index 7afe6e1a4b4ef..d425216317fc8 100644 --- a/test/framework/src/main/java/org/elasticsearch/cluster/coordination/AbstractCoordinatorTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/cluster/coordination/AbstractCoordinatorTestCase.java @@ -518,7 +518,7 @@ void stabilise(long stabilisationDurationMillis) { final ClusterNode leader = getAnyLeader(); final long leaderTerm = leader.coordinator.getCurrentTerm(); - final int pendingTaskCount = leader.masterService.getFakeMasterServicePendingTaskCount(); + final int pendingTaskCount = leader.getPendingTaskCount(); runFor((pendingTaskCount + 1) * DEFAULT_CLUSTER_STATE_UPDATE_DELAY, "draining task queue"); final Matcher isEqualToLeaderVersion = equalTo(leader.coordinator.getLastAcceptedState().getVersion()); @@ -1282,6 +1282,10 @@ void allowClusterStateApplicationFailure() { boolean deliverBlackholedRequests() { return mockTransport.deliverBlackholedRequests(); } + + int getPendingTaskCount() { + return masterService.getFakeMasterServicePendingTaskCount(); + } } private List provideSeedHosts(SeedHostsProvider.HostsResolver ignored) {