Skip to content

Commit 8a6a38a

Browse files
committed
Trying to avoid flaky test on PojoServiceIt
1 parent c374852 commit 8a6a38a

File tree

2 files changed

+23
-15
lines changed
  • quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows

2 files changed

+23
-15
lines changed

quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/PojoServiceIT.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,22 @@ void testTypesPojo() throws Exception {
150150
}
151151

152152
private void doIt(String flowName) throws Exception {
153-
Map<String, Object> body = new HashMap<>();
154-
body.put("name", "javierito");
155-
body.put("age", 666);
156-
given()
157-
.contentType(ContentType.JSON)
158-
.when()
159-
.body(Collections.singletonMap("workflowdata", body))
160-
.post("/" + flowName)
161-
.then()
162-
.statusCode(201)
163-
.body("id", notNullValue())
164-
.body("workflowdata.name", is("javieritoPerson"))
165-
.body("workflowdata.age", nullValue());
166153
JsonPath processInstanceEventContent = waitForKogitoProcessInstanceEvent(kafkaClient, ProcessInstanceVariableDataEvent.class,
167-
e -> flowName.equals(e.get("kogitoprocid")) && "workflowdata".equals(e.get("data.variableName")), true);
154+
e -> flowName.equals(e.get("kogitoprocid")) && "workflowdata".equals(e.get("data.variableName")), true, () -> {
155+
Map<String, Object> body = new HashMap<>();
156+
body.put("name", "javierito");
157+
body.put("age", 666);
158+
given()
159+
.contentType(ContentType.JSON)
160+
.when()
161+
.body(Collections.singletonMap("workflowdata", body))
162+
.post("/" + flowName)
163+
.then()
164+
.statusCode(201)
165+
.body("id", notNullValue())
166+
.body("workflowdata.name", is("javieritoPerson"))
167+
.body("workflowdata.age", nullValue());
168+
});
168169
Map workflowDataMap = processInstanceEventContent.getMap("data.variableValue");
169170
assertThat(workflowDataMap).hasSize(1);
170171
assertThat(workflowDataMap).containsEntry("name", "javieritoPerson");

quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-integration-test/src/test/java/org/kie/kogito/quarkus/workflows/WorkflowTestUtils.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ public static JsonPath waitForKogitoProcessInstanceEvent(KafkaTestClient kafkaCl
4747

4848
public static <T extends DataEvent<?>> JsonPath waitForKogitoProcessInstanceEvent(KafkaTestClient kafkaClient, Class<T> eventType, Predicate<JsonPath> predicate, boolean shutdownAfterConsume)
4949
throws Exception {
50+
return waitForKogitoProcessInstanceEvent(kafkaClient, eventType, predicate, shutdownAfterConsume, () -> {
51+
});
52+
}
53+
54+
public static <T extends DataEvent<?>> JsonPath waitForKogitoProcessInstanceEvent(KafkaTestClient kafkaClient, Class<T> eventType, Predicate<JsonPath> predicate, boolean shutdownAfterConsume,
55+
Runnable runnable) throws InterruptedException {
5056
final CountDownLatch countDownLatch = new CountDownLatch(1);
5157
final AtomicReference<JsonPath> cloudEvent = new AtomicReference<>();
5258

@@ -61,12 +67,13 @@ public static <T extends DataEvent<?>> JsonPath waitForKogitoProcessInstanceEven
6167
countDownLatch.countDown();
6268
}
6369
});
70+
71+
runnable.run();
6472
// give some time to consume the event
6573
assertThat(countDownLatch.await(TIME_OUT_SECONDS, TimeUnit.SECONDS)).isTrue();
6674
if (shutdownAfterConsume) {
6775
kafkaClient.shutdown();
6876
}
6977
return cloudEvent.get();
7078
}
71-
7279
}

0 commit comments

Comments
 (0)