Skip to content

Commit 040971a

Browse files
authored
Fix MasterServiceTests.testClusterStateUpdateLogging (elastic#38116) (elastic#38141)
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 elastic#23739
1 parent c6173d3 commit 040971a

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,16 @@ public void testClusterStateUpdateLogging() throws Exception {
325325
MasterService.class.getCanonicalName(),
326326
Level.DEBUG,
327327
"*processing [test3]: took [3s] done publishing updated cluster state (version: *, uuid: *)"));
328+
mockAppender.addExpectation(
329+
new MockLogAppender.SeenEventExpectation(
330+
"test4",
331+
MasterService.class.getCanonicalName(),
332+
Level.DEBUG,
333+
"*processing [test4]: took [0s] no change in cluster state"));
328334

329335
Logger clusterLogger = LogManager.getLogger(MasterService.class);
330336
Loggers.addAppender(clusterLogger, mockAppender);
331337
try {
332-
final CountDownLatch latch = new CountDownLatch(4);
333338
masterService.currentTimeOverride = System.nanoTime();
334339
masterService.submitStateUpdateTask("test1", new ClusterStateUpdateTask() {
335340
@Override
@@ -339,9 +344,7 @@ public ClusterState execute(ClusterState currentState) throws Exception {
339344
}
340345

341346
@Override
342-
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
343-
latch.countDown();
344-
}
347+
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) { }
345348

346349
@Override
347350
public void onFailure(String source, Exception e) {
@@ -361,9 +364,7 @@ public void clusterStateProcessed(String source, ClusterState oldState, ClusterS
361364
}
362365

363366
@Override
364-
public void onFailure(String source, Exception e) {
365-
latch.countDown();
366-
}
367+
public void onFailure(String source, Exception e) { }
367368
});
368369
masterService.submitStateUpdateTask("test3", new ClusterStateUpdateTask() {
369370
@Override
@@ -373,9 +374,7 @@ public ClusterState execute(ClusterState currentState) {
373374
}
374375

375376
@Override
376-
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
377-
latch.countDown();
378-
}
377+
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) { }
379378

380379
@Override
381380
public void onFailure(String source, Exception e) {
@@ -391,21 +390,18 @@ public ClusterState execute(ClusterState currentState) {
391390
}
392391

393392
@Override
394-
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
395-
latch.countDown();
396-
}
393+
public void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) { }
397394

398395
@Override
399396
public void onFailure(String source, Exception e) {
400397
fail();
401398
}
402399
});
403-
latch.await();
400+
assertBusy(mockAppender::assertAllExpectationsMatched);
404401
} finally {
405402
Loggers.removeAppender(clusterLogger, mockAppender);
406403
mockAppender.stop();
407404
}
408-
mockAppender.assertAllExpectationsMatched();
409405
}
410406

411407
public void testClusterStateBatchedUpdates() throws BrokenBarrierException, InterruptedException {

0 commit comments

Comments
 (0)