Skip to content

Commit c67a966

Browse files
authored
Fix MasterServiceTests.testClusterStateUpdateLogging (#38116)
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
1 parent f3cde06 commit c67a966

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

server/src/test/java/org/elasticsearch/cluster/service/MasterServiceTests.java

+11-15
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,16 @@ public void testClusterStateUpdateLogging() throws Exception {
328328
MasterService.class.getCanonicalName(),
329329
Level.DEBUG,
330330
"*processing [test3]: took [3s] done publishing updated cluster state (version: *, uuid: *)"));
331+
mockAppender.addExpectation(
332+
new MockLogAppender.SeenEventExpectation(
333+
"test4",
334+
MasterService.class.getCanonicalName(),
335+
Level.DEBUG,
336+
"*processing [test4]: took [0s] no change in cluster state"));
331337

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

344349
@Override
345-
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
346-
latch.countDown();
347-
}
350+
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) { }
348351

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

366369
@Override
367-
public void onFailure(String source, Exception e) {
368-
latch.countDown();
369-
}
370+
public void onFailure(String source, Exception e) { }
370371
});
371372
masterService.submitStateUpdateTask("test3", new ClusterStateUpdateTask() {
372373
@Override
@@ -376,9 +377,7 @@ public ClusterState execute(ClusterState currentState) {
376377
}
377378

378379
@Override
379-
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
380-
latch.countDown();
381-
}
380+
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) { }
382381

383382
@Override
384383
public void onFailure(String source, Exception e) {
@@ -394,21 +393,18 @@ public ClusterState execute(ClusterState currentState) {
394393
}
395394

396395
@Override
397-
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
398-
latch.countDown();
399-
}
396+
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) { }
400397

401398
@Override
402399
public void onFailure(String source, Exception e) {
403400
fail();
404401
}
405402
});
406-
latch.await();
403+
assertBusy(mockAppender::assertAllExpectationsMatched);
407404
} finally {
408405
Loggers.removeAppender(clusterLogger, mockAppender);
409406
mockAppender.stop();
410407
}
411-
mockAppender.assertAllExpectationsMatched();
412408
}
413409

414410
public void testClusterStateBatchedUpdates() throws BrokenBarrierException, InterruptedException {

0 commit comments

Comments
 (0)