Skip to content

Commit

Permalink
Attempt to fix flaky testDeleteAllDynamicJobs test
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwilshire committed Oct 25, 2024
1 parent 008b3f1 commit 33e59a8
Showing 1 changed file with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.doNothing;

import com.box.l10n.mojito.JSR310Migration;
import com.box.l10n.mojito.cli.CLITestBase;
Expand All @@ -11,22 +13,41 @@
import com.box.l10n.mojito.quartz.QuartzService;
import java.time.ZonedDateTime;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.mockito.Mockito;
import org.quartz.SchedulerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.SpyBean;

public class QuartzJobsDeleteCommandTest extends CLITestBase {

/** logger */
static Logger logger = LoggerFactory.getLogger(QuartzJobsDeleteCommandTest.class);

@Autowired QuartzPollableTaskScheduler quartzPollableTaskScheduler;
@SpyBean QuartzPollableTaskScheduler quartzPollableTaskScheduler;

@Autowired QuartzService quartzService;

@AfterEach
public void afterEach() {
Mockito.reset(quartzPollableTaskScheduler);
}

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

// Don't allow job scheduling unless it's the two jobs below
doNothing()
.when(quartzPollableTaskScheduler)
.scheduleJob(
argThat(
arg ->
!arg.getUniqueId().equals(testJobName1)
&& !arg.getUniqueId().equals(testJobName2)));
waitForCondition(
"Should be no dynamic jobs",
() -> {
Expand All @@ -42,9 +63,6 @@ public void testDeleteAllDynamicJobs() throws Exception {
assertTrue("Should show no jobs", outputCapture.toString().contains("None"));
assertTrue(quartzService.getDynamicJobs().isEmpty());

String testJobName1 = testIdWatcher.getEntityName("1");
String testJobName2 = testIdWatcher.getEntityName("2");

quartzPollableTaskScheduler.scheduleJob(
QuartzJobInfo.newBuilder(AJob.class)
.withTriggerStartDate(JSR310Migration.dateTimePlusAsDate(ZonedDateTime.now(), 100000))
Expand Down

0 comments on commit 33e59a8

Please sign in to comment.