Skip to content

Commit

Permalink
chore(update-tests): use awaitility instead of TestUtil
Browse files Browse the repository at this point in the history
(cherry picked from commit 0cb446b)
  • Loading branch information
npepinpe authored and github-actions[bot] committed Nov 23, 2020
1 parent 485434a commit e5ff1e6
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 40 deletions.
4 changes: 2 additions & 2 deletions update-tests/src/test/java/io/zeebe/test/UpdateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ void oldGatewayWithNewBroker(final String name, final UpdateTestCase testCase) {
@Timeout(value = 5, unit = TimeUnit.MINUTES)
@ParameterizedTest(name = "{0}")
@ArgumentsSource(UpdateTestCaseProvider.class)
void upgradeWithSnapshot(final String name, final UpdateTestCase testCase) {
void updateWithSnapshot(final String name, final UpdateTestCase testCase) {
updateZeebe(testCase, true);
}

@Timeout(value = 5, unit = TimeUnit.MINUTES)
@ParameterizedTest(name = "{0}")
@ArgumentsSource(UpdateTestCaseProvider.class)
void upgradeWithoutSnapshot(final String name, final UpdateTestCase testCase) {
void updateWithoutSnapshot(final String name, final UpdateTestCase testCase) {
updateZeebe(testCase, false);
}

Expand Down
124 changes: 86 additions & 38 deletions update-tests/src/test/java/io/zeebe/test/UpdateTestCaseProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import io.zeebe.model.bpmn.Bpmn;
import io.zeebe.model.bpmn.BpmnModelInstance;
import io.zeebe.test.UpdateTestCase.TestCaseBuilder;
import io.zeebe.test.util.TestUtil;
import io.zeebe.util.collection.Tuple;
import java.time.Duration;
import java.util.Map;
import java.util.stream.Stream;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
Expand Down Expand Up @@ -72,9 +72,7 @@ public Stream<? extends Arguments> provideArguments(final ExtensionContext conte
.beforeUpgrade(
state -> {
publishMessage(state, -1L, -1L);

TestUtil.waitUntil(
() -> state.hasElementInState("event-subprocess", "ELEMENT_COMPLETED"));
awaitElementInState(state, "event-subprocess", "ELEMENT_COMPLETED");

return activateJob(state);
})
Expand All @@ -84,7 +82,7 @@ public Stream<? extends Arguments> provideArguments(final ExtensionContext conte
.name("timer")
.deployWorkflow(timerWorkflow())
.beforeUpgrade(this::awaitTimerCreation)
.afterUpgrade(this::timerTriggered)
.afterUpgrade(this::awaitTimerTriggered)
.done(),
scenario()
.name("incident")
Expand All @@ -110,7 +108,8 @@ public Stream<? extends Arguments> provideArguments(final ExtensionContext conte
.latestVersion()
.variables(Map.of("key", "123"))
.send();
TestUtil.waitUntil(() -> state.hasLogContaining(MESSAGE, "CORRELATED"));

awaitMessageCorrelation(state, MESSAGE);
})
.done(),
scenario()
Expand All @@ -121,7 +120,7 @@ public Stream<? extends Arguments> provideArguments(final ExtensionContext conte
.createInstance()
.afterUpgrade(
(state, wfKey, key) -> {
TestUtil.waitUntil(() -> state.hasElementInState(JOB, "CREATED"));
awaitElementInState(state, JOB, "CREATED");

final var jobsResponse =
state
Expand All @@ -133,14 +132,14 @@ public Stream<? extends Arguments> provideArguments(final ExtensionContext conte
.join();
assertThat(jobsResponse.getJobs()).hasSize(1);

TestUtil.waitUntil(() -> state.hasElementInState(JOB, "ACTIVATED"));

awaitElementInState(state, JOB, "ACTIVATED");
state
.client()
.newCompleteCommand(jobsResponse.getJobs().get(0).getKey())
.send()
.join();
TestUtil.waitUntil(() -> state.hasLogContaining(CHILD_PROCESS_ID, "COMPLETED"));

awaitChildProcessCompleted(state, CHILD_PROCESS_ID);
})
.done(),
scenario()
Expand Down Expand Up @@ -191,13 +190,13 @@ private BpmnModelInstance jobWorkflow() {
}

private long activateJob(final ContainerState state) {
TestUtil.waitUntil(() -> state.hasElementInState(JOB, "CREATED"));
awaitElementInState(state, JOB, "CREATED");

final ActivateJobsResponse jobsResponse =
state.client().newActivateJobsCommand().jobType(TASK).maxJobsToActivate(1).send().join();
assertThat(jobsResponse.getJobs()).hasSize(1);

TestUtil.waitUntil(() -> state.hasElementInState(JOB, "ACTIVATED"));
awaitElementInState(state, JOB, "ACTIVATED");
return jobsResponse.getJobs().get(0).getKey();
}

Expand All @@ -214,11 +213,6 @@ private BpmnModelInstance messageWorkflow() {
.done();
}

private long awaitOpenMessageSubscription(final ContainerState state) {
TestUtil.waitUntil(() -> state.hasLogContaining("MESSAGE_SUBSCRIPTION", "OPENED"));
return -1L;
}

private void publishMessage(
final ContainerState state, final long wfInstanceKey, final long key) {
state
Expand All @@ -231,7 +225,7 @@ private void publishMessage(
.send()
.join();

TestUtil.waitUntil(() -> state.hasMessageInState(MESSAGE, "PUBLISHED"));
awaitMessageIsInState(state, MESSAGE, "PUBLISHED");
}

private BpmnModelInstance msgStartWorkflow() {
Expand All @@ -242,11 +236,6 @@ private BpmnModelInstance msgStartWorkflow() {
.done();
}

private long awaitStartMessageSubscription(final ContainerState state) {
TestUtil.waitUntil(() -> state.hasLogContaining("MESSAGE_START_EVENT_SUBSCRIPTION", "OPENED"));
return -1L;
}

private BpmnModelInstance timerWorkflow() {
return Bpmn.createExecutableProcess(PROCESS_ID)
.startEvent()
Expand All @@ -255,28 +244,13 @@ private BpmnModelInstance timerWorkflow() {
.done();
}

private long awaitTimerCreation(final ContainerState state) {
TestUtil.waitUntil(() -> state.hasLogContaining("TIMER", "CREATED"));
return -1L;
}

private void timerTriggered(
final ContainerState state, final long wfInstanceKey, final long key) {
TestUtil.waitUntil(() -> state.hasLogContaining("TIMER", "TRIGGERED"));
}

private BpmnModelInstance incidentWorkflow() {
return Bpmn.createExecutableProcess(PROCESS_ID)
.startEvent()
.serviceTask("failingTask", t -> t.zeebeJobType(TASK).zeebeInputExpression("foo", "foo"))
.done();
}

private long awaitIncidentCreation(final ContainerState state) {
TestUtil.waitUntil(() -> state.hasLogContaining("INCIDENT", "CREATED"));
return state.getIncidentKey();
}

private void resolveIncident(
final ContainerState state, final long wfInstanceKey, final long key) {
state
Expand Down Expand Up @@ -308,6 +282,80 @@ private BpmnModelInstance childWorkflow() {
.done();
}

private void awaitMessageCorrelation(final ContainerState state, final String message) {
Awaitility.await(String.format("until message %s is correlated", message))
.atMost(Duration.ofSeconds(5))
.pollInterval(Duration.ofMillis(200))
.until(() -> state.hasLogContaining(message, "CORRELATED"));
}

private void awaitMessageIsInState(
final ContainerState state, final String message, final String messageState) {
Awaitility.await(String.format("until message %s is %s", message, messageState))
.atMost(Duration.ofSeconds(5))
.pollInterval(Duration.ofMillis(200))
.until(() -> state.hasMessageInState(message, messageState));
}

private long awaitOpenMessageSubscription(final ContainerState state) {
Awaitility.await("until a message subscription is opened")
.atMost(Duration.ofSeconds(5))
.pollInterval(Duration.ofMillis(200))
.until(() -> state.hasLogContaining("MESSAGE_SUBSCRIPTION", "OPENED"));

return -1L;
}

private long awaitStartMessageSubscription(final ContainerState state) {
Awaitility.await("until a start event message subscription is opened")
.atMost(Duration.ofSeconds(5))
.pollInterval(Duration.ofMillis(200))
.until(() -> state.hasLogContaining("MESSAGE_START_EVENT_SUBSCRIPTION", "OPENED"));

return -1L;
}

private long awaitTimerCreation(final ContainerState state) {
Awaitility.await("until a timer is created")
.atMost(Duration.ofSeconds(5))
.pollInterval(Duration.ofMillis(200))
.until(() -> state.hasLogContaining("TIMER", "CREATED"));

return -1L;
}

private void awaitTimerTriggered(
final ContainerState state, final long wfInstanceKey, final long key) {
Awaitility.await("until a timer is created")
.atMost(Duration.ofSeconds(5))
.pollInterval(Duration.ofMillis(200))
.until(() -> state.hasLogContaining("TIMER", "TRIGGERED"));
}

private void awaitChildProcessCompleted(final ContainerState state, final String processId) {
Awaitility.await("until the child process is completed")
.atMost(Duration.ofSeconds(5))
.pollInterval(Duration.ofMillis(200))
.until(() -> state.hasLogContaining(CHILD_PROCESS_ID, "COMPLETED"));
}

private long awaitIncidentCreation(final ContainerState state) {
Awaitility.await("until an incident is created")
.atMost(Duration.ofSeconds(5))
.pollInterval(Duration.ofMillis(200))
.until(() -> state.hasLogContaining("INCIDENT", "CREATED"));

return state.getIncidentKey();
}

private void awaitElementInState(
final ContainerState state, final String elementId, final String elementState) {
Awaitility.await(String.format("until element %s is in state %s", elementId, elementState))
.atMost(Duration.ofSeconds(5))
.pollInterval(Duration.ofMillis(200))
.until(() -> state.hasElementInState(elementId, elementState));
}

private TestCaseBuilder scenario() {
return UpdateTestCase.builder();
}
Expand Down

0 comments on commit e5ff1e6

Please sign in to comment.