@@ -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