Skip to content

Commit

Permalink
[I18N-1311] Fix for flaky testDeleteAllDynamicJobs test (#175)
Browse files Browse the repository at this point in the history
* Logging for flaky test

* Fix flaky testDeleteAllDynamicJobs
  • Loading branch information
mattwilshire authored Oct 29, 2024
1 parent feef899 commit f0b6b55
Showing 1 changed file with 10 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import com.box.l10n.mojito.quartz.QuartzPollableTaskScheduler;
import com.box.l10n.mojito.quartz.QuartzService;
import java.time.ZonedDateTime;
import java.util.function.Predicate;
import org.junit.Test;
import org.quartz.SchedulerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -26,22 +26,7 @@ public class QuartzJobsDeleteCommandTest extends CLITestBase {
@Autowired QuartzService quartzService;

@Test
public void testDeleteAllDynamicJobs() throws Exception {
waitForCondition(
"Should be no dynamic jobs",
() -> {
boolean result = false;
try {
result = quartzService.getDynamicJobs().isEmpty();
} catch (SchedulerException e) {
}
return result;
});

getL10nJCommander().run("quartz-jobs-view");
assertTrue("Should show no jobs", outputCapture.toString().contains("None"));
assertTrue(quartzService.getDynamicJobs().isEmpty());

public void testDeleteDynamicJobs() throws Exception {
String testJobName1 = testIdWatcher.getEntityName("1");
String testJobName2 = testIdWatcher.getEntityName("2");

Expand All @@ -59,11 +44,16 @@ public void testDeleteAllDynamicJobs() throws Exception {
getL10nJCommander().run("quartz-jobs-view");
assertTrue("Should show 1 job", outputCapture.toString().contains("AJob_" + testJobName1));
assertTrue("Should show 1 job", outputCapture.toString().contains("AJob_" + testJobName2));
assertEquals(2L, quartzService.getDynamicJobs().size());

Predicate<String> jobsFilter =
job -> job.contains("AJob_" + testJobName1) || job.contains("AJob_" + testJobName2);

assertEquals(2L, quartzService.getDynamicJobs().stream().filter(jobsFilter).count());
getL10nJCommander().run("quartz-jobs-delete");
getL10nJCommander().run("quartz-jobs-view");
assertEquals(0L, quartzService.getDynamicJobs().size());
// Although all jobs should be deleted, they must be filtered as the dynamic
// RepositoryStatistics job could have started after the deletion which would make this test
// flaky
assertEquals(0L, quartzService.getDynamicJobs().stream().filter(jobsFilter).count());
}

public static class AJob extends QuartzPollableJob<Void, Void> {
Expand Down

0 comments on commit f0b6b55

Please sign in to comment.