Skip to content

Commit

Permalink
Scheduler - try to fix flaky tests
Browse files Browse the repository at this point in the history
- resolves quarkusio#16532
  • Loading branch information
mkouba committed Apr 15, 2021
1 parent 52a0320 commit bb6d7ed
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.quartz.test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand All @@ -25,8 +26,7 @@ public class DisabledScheduledMethodTest {

@Test
public void testNoSchedulerInvocations() throws InterruptedException {
Thread.sleep(100);
Jobs.LATCH.await(500, TimeUnit.MILLISECONDS);
assertTrue(Jobs.LATCH.await(2, TimeUnit.SECONDS));
assertEquals(0, Jobs.executionCounter);
}

Expand All @@ -46,7 +46,7 @@ void disabledByDefault() {
executionCounter++;
}

@Scheduled(every = "0.001s")
@Scheduled(every = "0.5s")
void enabled() {
LATCH.countDown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class PropertyDefaultValueSchedulerTest {

@Test
public void testDefaultIdentity() throws InterruptedException {
assertTrue(Jobs.LATCH.await(500, TimeUnit.MILLISECONDS), "Scheduler was not triggered");
assertTrue(Jobs.LATCH.await(5, TimeUnit.SECONDS), "Scheduler was not triggered");
assertNotNull(Jobs.execution);
final String actualIdentity = Jobs.execution.getTrigger().getId();
assertTrue(actualIdentity.contains(EXPECTED_IDENTITY),
Expand All @@ -40,12 +40,12 @@ static class Jobs {

static final CountDownLatch LATCH = new CountDownLatch(1);

static ScheduledExecution execution;
static volatile ScheduledExecution execution;

@Scheduled(every = "0.001s", identity = "{nonexistent:${PropertyDefaultValueSchedulerTest.default}}")
void trigger(ScheduledExecution execution) {
if (this.execution == null) {
this.execution = execution;
@Scheduled(every = "0.5s", identity = "{nonexistent:${PropertyDefaultValueSchedulerTest.default}}")
void trigger(ScheduledExecution exec) {
if (execution == null) {
execution = exec;
}
LATCH.countDown();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.scheduler.test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand All @@ -25,8 +26,7 @@ public class DisabledScheduledMethodTest {

@Test
public void testNoSchedulerInvocations() throws InterruptedException {
Thread.sleep(100);
Jobs.LATCH.await(500, TimeUnit.MILLISECONDS);
assertTrue(Jobs.LATCH.await(2, TimeUnit.SECONDS));
assertEquals(0, Jobs.executionCounter);
}

Expand All @@ -46,7 +46,7 @@ void disabledByDefault() {
executionCounter++;
}

@Scheduled(every = "0.001s")
@Scheduled(every = "0.5s")
void enabled() {
LATCH.countDown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class PropertyDefaultValueSchedulerTest {

@Test
public void testDefaultIdentity() throws InterruptedException {
assertTrue(Jobs.LATCH.await(500, TimeUnit.MILLISECONDS), "Scheduler was not triggered");
assertTrue(Jobs.LATCH.await(5, TimeUnit.SECONDS), "Scheduler was not triggered");
assertNotNull(Jobs.execution);
assertEquals(EXPECTED_IDENTITY, Jobs.execution.getTrigger().getId());
}
Expand All @@ -39,12 +39,12 @@ static class Jobs {

static final CountDownLatch LATCH = new CountDownLatch(1);

static ScheduledExecution execution;
static volatile ScheduledExecution execution;

@Scheduled(every = "0.001s", identity = "{nonexistent:${PropertyDefaultValueSchedulerTest.default}}")
void trigger(ScheduledExecution execution) {
if (this.execution == null) {
this.execution = execution;
@Scheduled(every = "0.5s", identity = "{nonexistent:${PropertyDefaultValueSchedulerTest.default}}")
void trigger(ScheduledExecution exec) {
if (execution == null) {
execution = exec;
}
LATCH.countDown();
}
Expand Down

0 comments on commit bb6d7ed

Please sign in to comment.