Skip to content

Commit

Permalink
Fix MasterServiceTests.testClusterStateUpdateLogging (#38116)
Browse files Browse the repository at this point in the history
This changes the test to not use a `CountDownlatch`, instead adding an assertion
for the final logging message and waiting until the `MockAppender` has seen it
before proceeding.

Related to df2c06f
Resolves #23739
  • Loading branch information
dakrone authored Feb 1, 2019
1 parent f3cde06 commit c67a966
Showing 1 changed file with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,16 @@ public void testClusterStateUpdateLogging() throws Exception {
MasterService.class.getCanonicalName(),
Level.DEBUG,
"*processing [test3]: took [3s] done publishing updated cluster state (version: *, uuid: *)"));
mockAppender.addExpectation(
new MockLogAppender.SeenEventExpectation(
"test4",
MasterService.class.getCanonicalName(),
Level.DEBUG,
"*processing [test4]: took [0s] no change in cluster state"));

Logger clusterLogger = LogManager.getLogger(MasterService.class);
Loggers.addAppender(clusterLogger, mockAppender);
try {
final CountDownLatch latch = new CountDownLatch(4);
masterService.currentTimeOverride = System.nanoTime();
masterService.submitStateUpdateTask("test1", new ClusterStateUpdateTask() {
@Override
Expand All @@ -342,9 +347,7 @@ public ClusterState execute(ClusterState currentState) throws Exception {
}

@Override
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
latch.countDown();
}
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) { }

@Override
public void onFailure(String source, Exception e) {
Expand All @@ -364,9 +367,7 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
}

@Override
public void onFailure(String source, Exception e) {
latch.countDown();
}
public void onFailure(String source, Exception e) { }
});
masterService.submitStateUpdateTask("test3", new ClusterStateUpdateTask() {
@Override
Expand All @@ -376,9 +377,7 @@ public ClusterState execute(ClusterState currentState) {
}

@Override
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
latch.countDown();
}
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) { }

@Override
public void onFailure(String source, Exception e) {
Expand All @@ -394,21 +393,18 @@ public ClusterState execute(ClusterState currentState) {
}

@Override
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
latch.countDown();
}
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) { }

@Override
public void onFailure(String source, Exception e) {
fail();
}
});
latch.await();
assertBusy(mockAppender::assertAllExpectationsMatched);
} finally {
Loggers.removeAppender(clusterLogger, mockAppender);
mockAppender.stop();
}
mockAppender.assertAllExpectationsMatched();
}

public void testClusterStateBatchedUpdates() throws BrokenBarrierException, InterruptedException {
Expand Down

0 comments on commit c67a966

Please sign in to comment.