Skip to content

Commit

Permalink
Better assertions (and longer run) in testSingleNodeDiscoveryStabilis…
Browse files Browse the repository at this point in the history
…esEvenWhenDisrupted
  • Loading branch information
DaveCTurner committed Sep 9, 2021
1 parent 07af588 commit aa14bb1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long> isEqualToLeaderVersion = equalTo(leader.coordinator.getLastAcceptedState().getVersion());
Expand Down Expand Up @@ -1282,6 +1282,10 @@ void allowClusterStateApplicationFailure() {
boolean deliverBlackholedRequests() {
return mockTransport.deliverBlackholedRequests();
}

int getPendingTaskCount() {
return masterService.getFakeMasterServicePendingTaskCount();
}
}

private List<TransportAddress> provideSeedHosts(SeedHostsProvider.HostsResolver ignored) {
Expand Down

0 comments on commit aa14bb1

Please sign in to comment.