Skip to content

Commit 54d707c

Browse files
authored
Fix leaking tests in HealthPeriodicLoggerTests (#134295)
At least one (`testClosingWhenRunInProgress`) test, but likely more, were leaking into other tests in `HealthPeriodicLoggerTests`. By triggering the health logger asynchronously in a separate thread, the actual health log would be logged in a subsequent test. `testOutputModeNoLogging` asserts that nothing is logged, so this leaking log would result in a test failure. We simply need to wait for the separate thread to finish before proceeding to the next test. Fixes #134200
1 parent 1ffad3a commit 54d707c

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,6 @@ tests:
510510
- class: org.elasticsearch.xpack.esql.qa.single_node.GenerativeForkIT
511511
method: test {csv-spec:inlinestats.MultiIndexInlinestatsOfMultiTypedField}
512512
issue: https://github.com/elastic/elasticsearch/issues/133973
513-
- class: org.elasticsearch.health.HealthPeriodicLoggerTests
514-
method: testOutputModeNoLogging
515-
issue: https://github.com/elastic/elasticsearch/issues/134200
516513
- class: org.elasticsearch.xpack.esql.qa.single_node.GenerativeForkIT
517514
method: test {csv-spec:spatial_shapes.ConvertFromStringParseError}
518515
issue: https://github.com/elastic/elasticsearch/issues/134254

server/src/test/java/org/elasticsearch/health/HealthPeriodicLoggerTests.java

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -436,23 +436,24 @@ public void testTryToLogHealthConcurrencyControlWithResults() throws Exception {
436436
SchedulerEngine.Event event = new SchedulerEngine.Event(HealthPeriodicLogger.HEALTH_PERIODIC_LOGGER_JOB_NAME, 0, 0);
437437

438438
// run it once, verify getHealth is called
439-
{
440-
Thread logHealthThread = new Thread(() -> testHealthPeriodicLogger.triggered(event));
441-
logHealthThread.start();
442-
// We wait to verify that the triggered even is in progress, then we block, so it will rename in progress
443-
assertBusy(() -> assertThat(getHealthCalled.get(), equalTo(1)));
444-
// We try to log again while it's in progress, we expect this run to be skipped
445-
assertFalse(testHealthPeriodicLogger.tryToLogHealth());
446-
// Unblock the first execution
447-
waitForSecondRun.countDown();
448-
}
439+
Thread logHealthThread = new Thread(() -> testHealthPeriodicLogger.triggered(event));
440+
logHealthThread.start();
441+
// We wait to verify that the triggered even is in progress, then we block, so it will rename in progress
442+
assertBusy(() -> assertThat(getHealthCalled.get(), equalTo(1)));
443+
// We try to log again while it's in progress, we expect this run to be skipped
444+
assertFalse(testHealthPeriodicLogger.tryToLogHealth());
445+
// Unblock the first execution
446+
waitForSecondRun.countDown();
449447

450448
// run it again, verify getHealth is called, because we are calling the results listener
451449
{
452450
waitForRelease.await();
453451
testHealthPeriodicLogger.triggered(event);
454452
assertBusy(() -> assertThat(getHealthCalled.get(), equalTo(2)));
455453
}
454+
455+
// Wait for the log thread to finish, to ensure it logs during this test and doesn't pollute other tests.
456+
logHealthThread.join();
456457
}
457458

458459
public void testTryToLogHealthConcurrencyControl() throws Exception {
@@ -485,11 +486,9 @@ public void testTryToLogHealthConcurrencyControl() throws Exception {
485486
SchedulerEngine.Event event = new SchedulerEngine.Event(HealthPeriodicLogger.HEALTH_PERIODIC_LOGGER_JOB_NAME, 0, 0);
486487

487488
// call it and verify that getHealth is called
488-
{
489-
Thread logHealthThread = new Thread(() -> testHealthPeriodicLogger.triggered(event));
490-
logHealthThread.start();
491-
assertBusy(() -> assertThat(getHealthCalled.get(), equalTo(1)));
492-
}
489+
Thread logHealthThread = new Thread(() -> testHealthPeriodicLogger.triggered(event));
490+
logHealthThread.start();
491+
assertBusy(() -> assertThat(getHealthCalled.get(), equalTo(1)));
493492

494493
// run it again, verify that it's skipped because the other one is in progress
495494
{
@@ -504,6 +503,9 @@ public void testTryToLogHealthConcurrencyControl() throws Exception {
504503
testHealthPeriodicLogger.triggered(event);
505504
assertBusy(() -> assertThat(getHealthCalled.get(), equalTo(2)));
506505
}
506+
507+
// Wait for the log thread to finish, to ensure it logs during this test and doesn't pollute other tests.
508+
logHealthThread.join();
507509
}
508510

509511
public void testTryToLogHealthConcurrencyControlWithException() throws Exception {
@@ -609,11 +611,9 @@ public void testClosingWhenRunInProgress() throws Exception {
609611
SchedulerEngine.Event event = new SchedulerEngine.Event(HealthPeriodicLogger.HEALTH_PERIODIC_LOGGER_JOB_NAME, 0, 0);
610612

611613
// call it and verify that getHealth is called
612-
{
613-
Thread logHealthThread = new Thread(() -> testHealthPeriodicLogger.triggered(event));
614-
logHealthThread.start();
615-
assertBusy(() -> assertTrue(testHealthPeriodicLogger.currentlyRunning()));
616-
}
614+
Thread logHealthThread = new Thread(() -> testHealthPeriodicLogger.triggered(event));
615+
logHealthThread.start();
616+
assertBusy(() -> assertTrue(testHealthPeriodicLogger.currentlyRunning()));
617617

618618
// stop and close it
619619
{
@@ -626,6 +626,9 @@ public void testClosingWhenRunInProgress() throws Exception {
626626
waitForCloseToBeTriggered.countDown();
627627
assertBusy(() -> assertEquals(Lifecycle.State.CLOSED, testHealthPeriodicLogger.lifecycleState()));
628628
}
629+
630+
// Wait for the log thread to finish, to ensure it logs during this test and doesn't pollute other tests.
631+
logHealthThread.join();
629632
}
630633
}
631634

0 commit comments

Comments
 (0)