Skip to content

Commit

Permalink
fix: wait for processing start when increasing time
Browse files Browse the repository at this point in the history
When we increase the time it takes some time before the engine has started processing again, and before it is writing new records to the stream. If we immediately wait for an idle state after increasting the time it will immediately say that it is idle, even though any potential timers have not yet been triggered.
By waiting for up to 1 second to see if the engine has started processing again we can make sure the timers have been triggered. After this we still need to wait until the engine is idle again, to not modify the existing functionality.
  • Loading branch information
remcowesterhoud committed Feb 28, 2022
1 parent 02df4df commit a6d916d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void testHasMessageStartEventNotBeenCorrelated() {
}

@Test
void testHasExpired() {
void testHasExpired() throws InterruptedException {
// given
Utilities.deployProcess(client, ProcessPackMessageEvent.RESOURCE_NAME);
final Duration timeToLive = Duration.ofDays(1);
Expand Down Expand Up @@ -260,7 +260,7 @@ void testHasExpiredFailure() {
}

@Test
void testHasNotExpiredFailure() {
void testHasNotExpiredFailure() throws InterruptedException {
// given
Utilities.deployProcess(client, ProcessPackMessageEvent.RESOURCE_NAME);
final Duration timeToLive = Duration.ofDays(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ProcessEventInspectionsTest {
private InMemoryEngine engine;

@Test
void testFindFirstProcessInstance() {
void testFindFirstProcessInstance() throws InterruptedException {
// given
final DeploymentEvent deploymentEvent =
Utilities.deployProcess(client, ProcessPackTimerStartEvent.RESOURCE_NAME);
Expand All @@ -43,7 +43,7 @@ void testFindFirstProcessInstance() {
}

@Test
void testFindLastProcessInstance() {
void testFindLastProcessInstance() throws InterruptedException {
// given
final DeploymentEvent deploymentEvent =
Utilities.deployProcess(client, ProcessPackTimerStartEvent.RESOURCE_NAME);
Expand All @@ -63,7 +63,7 @@ void testFindLastProcessInstance() {
}

@Test
void testFindFirstProcessInstance_wrongTimer() {
void testFindFirstProcessInstance_wrongTimer() throws InterruptedException {
// given
Utilities.deployProcess(client, ProcessPackTimerStartEvent.RESOURCE_NAME);

Expand All @@ -79,7 +79,7 @@ void testFindFirstProcessInstance_wrongTimer() {
}

@Test
void testFindProcessInstance_highIndex() {
void testFindProcessInstance_highIndex() throws InterruptedException {
// given
Utilities.deployProcess(client, ProcessPackTimerStartEvent.RESOURCE_NAME);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void testHasMessageStartEventNotBeenCorrelated() {
}

@Test
void testHasExpired() {
void testHasExpired() throws InterruptedException {
// given
Utilities.deployProcess(client, ProcessPackMessageEvent.RESOURCE_NAME);
final Duration timeToLive = Duration.ofDays(1);
Expand Down Expand Up @@ -260,7 +260,7 @@ void testHasExpiredFailure() {
}

@Test
void testHasNotExpiredFailure() {
void testHasNotExpiredFailure() throws InterruptedException {
// given
Utilities.deployProcess(client, ProcessPackMessageEvent.RESOURCE_NAME);
final Duration timeToLive = Duration.ofDays(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ProcessEventInspectionsTest {
private InMemoryEngine engine;

@Test
void testFindFirstProcessInstance() {
void testFindFirstProcessInstance() throws InterruptedException {
// given
final DeploymentEvent deploymentEvent =
Utilities.deployProcess(client, ProcessPackTimerStartEvent.RESOURCE_NAME);
Expand All @@ -43,7 +43,7 @@ void testFindFirstProcessInstance() {
}

@Test
void testFindLastProcessInstance() {
void testFindLastProcessInstance() throws InterruptedException {
// given
final DeploymentEvent deploymentEvent =
Utilities.deployProcess(client, ProcessPackTimerStartEvent.RESOURCE_NAME);
Expand All @@ -63,7 +63,7 @@ void testFindLastProcessInstance() {
}

@Test
void testFindFirstProcessInstance_wrongTimer() {
void testFindFirstProcessInstance_wrongTimer() throws InterruptedException {
// given
Utilities.deployProcess(client, ProcessPackTimerStartEvent.RESOURCE_NAME);

Expand All @@ -79,7 +79,7 @@ void testFindFirstProcessInstance_wrongTimer() {
}

@Test
void testFindProcessInstance_highIndex() {
void testFindProcessInstance_highIndex() throws InterruptedException {
// given
Utilities.deployProcess(client, ProcessPackTimerStartEvent.RESOURCE_NAME);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;

public class Utilities {
Expand Down Expand Up @@ -149,15 +150,16 @@ public static PublishMessageResponse sendMessage(
return response;
}

public static void increaseTime(final InMemoryEngine engine, final Duration duration) {
public static void increaseTime(final InMemoryEngine engine, final Duration duration)
throws InterruptedException {
engine.increaseTime(duration);
try {
// we need to wait some physical time so that InMemoryEngine has a chance to fire the timers
Thread.sleep(100);
} catch (InterruptedException e) {
// do nothing
engine.waitForProcessingState(Duration.ofMillis(250));
waitForIdleState(engine);
} catch (TimeoutException e) {
// Do nothing. We've waited up to 250 ms for processing to start, if it didn't start in this
// time the engine probably has not got anything left to process.
}
waitForIdleState(engine);
}

public static void completeTask(
Expand Down

0 comments on commit a6d916d

Please sign in to comment.