Skip to content

Commit

Permalink
Fix flaky testDeleteAllDynamicJobs
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwilshire committed Oct 29, 2024
1 parent c5260de commit 41793f5
Showing 1 changed file with 9 additions and 26 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,24 +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");
String output = outputCapture.toString();
System.out.println("LOG : testDeleteAllDynamicJobs : quartz-jobs-view response : " + output);
assertTrue("Should show no jobs", output.contains("None"));
assertTrue(quartzService.getDynamicJobs().isEmpty());

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

Expand All @@ -62,15 +45,15 @@ public void testDeleteAllDynamicJobs() throws Exception {
assertTrue("Should show 1 job", outputCapture.toString().contains("AJob_" + testJobName1));
assertTrue("Should show 1 job", outputCapture.toString().contains("AJob_" + testJobName2));

for (String dyanmicJob : quartzService.getDynamicJobs()) {
System.out.println("LOG : testDeleteAllDynamicJobs : " + dyanmicJob);
}

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 41793f5

Please sign in to comment.