Skip to content

Commit 34aba31

Browse files
committed
Add awaitability on flacky tests
Signed-off-by: Ricardo Zanini <[email protected]>
1 parent 57b1e70 commit 34aba31

File tree

3 files changed

+47
-29
lines changed

3 files changed

+47
-29
lines changed

impl/test/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
<groupId>com.squareup.okhttp3</groupId>
5858
<artifactId>mockwebserver</artifactId>
5959
</dependency>
60+
<dependency>
61+
<groupId>org.awaitility</groupId>
62+
<artifactId>awaitility</artifactId>
63+
</dependency>
6064
</dependencies>
6165
<build>
6266
<plugins>

impl/test/src/test/java/io/serverlessworkflow/impl/test/LifeCycleEventsTest.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import static org.assertj.core.api.Assertions.assertThat;
1919
import static org.assertj.core.api.Assertions.catchThrowableOfType;
20+
import static org.awaitility.Awaitility.await;
2021

2122
import io.cloudevents.CloudEvent;
2223
import io.cloudevents.core.data.PojoCloudEventData;
@@ -41,8 +42,10 @@
4142
import io.serverlessworkflow.impl.lifecycle.ce.WorkflowStartedCEData;
4243
import io.serverlessworkflow.impl.lifecycle.ce.WorkflowSuspendedCEData;
4344
import java.io.IOException;
45+
import java.time.Duration;
4446
import java.util.Collection;
4547
import java.util.Map;
48+
import java.util.Objects;
4649
import java.util.Optional;
4750
import java.util.concurrent.CompletableFuture;
4851
import java.util.concurrent.CompletionException;
@@ -211,14 +214,17 @@ void testError() throws IOException {
211214
}
212215

213216
private <T> T assertPojoInCE(String type, Class<T> clazz) {
214-
Thread.yield();
215-
Optional<CloudEvent> event =
216-
publishedEvents.stream().filter(ev -> ev.getType().equals(type)).findAny();
217-
assertThat(event)
218-
.hasValueSatisfying(ce -> assertThat(ce.getData()).isInstanceOf(PojoCloudEventData.class));
219-
assertThat(event)
220-
.hasValueSatisfying(
221-
ce -> assertThat(((PojoCloudEventData) ce.getData()).getValue()).isInstanceOf(clazz));
222-
return clazz.cast(((PojoCloudEventData) event.orElseThrow().getData()).getValue());
217+
CloudEvent ce =
218+
await()
219+
.atMost(Duration.ofSeconds(2))
220+
.pollInterval(Duration.ofMillis(10))
221+
.until(
222+
() -> publishedEvents.stream().filter(ev -> ev.getType().equals(type)).findAny(),
223+
Optional::isPresent)
224+
.orElseThrow();
225+
assertThat(ce.getData()).isInstanceOf(PojoCloudEventData.class);
226+
Object pojo = ((PojoCloudEventData<?>) Objects.requireNonNull(ce.getData())).getValue();
227+
assertThat(pojo).isInstanceOf(clazz);
228+
return clazz.cast(pojo);
223229
}
224230
}

pom.xml

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45

56
<groupId>io.serverlessworkflow</groupId>
@@ -36,18 +37,18 @@
3637
<tag>HEAD</tag>
3738
</scm>
3839

39-
<modules>
40-
<module>api</module>
41-
<module>impl</module>
42-
<module>types</module>
43-
<module>annotations</module>
44-
<module>generators</module>
45-
<module>serialization</module>
46-
<module>examples</module>
47-
<module>experimental</module>
48-
<module>fluent</module>
49-
<module>mermaid</module>
50-
</modules>
40+
<modules>
41+
<module>api</module>
42+
<module>impl</module>
43+
<module>types</module>
44+
<module>annotations</module>
45+
<module>generators</module>
46+
<module>serialization</module>
47+
<module>examples</module>
48+
<module>experimental</module>
49+
<module>fluent</module>
50+
<module>mermaid</module>
51+
</modules>
5152

5253
<properties>
5354
<java.version>17</java.version>
@@ -77,6 +78,7 @@
7778

7879

7980
<!-- Dependencies versions, please keep in alphabetical order -->
81+
<version.awaitility>4.2.0</version.awaitility>
8082
<version.ch.qos.logback>1.5.18</version.ch.qos.logback>
8183
<version.com.fasterxml.jackson>2.20.0</version.com.fasterxml.jackson>
8284
<version.com.fasterxml.jackson.annotations>2.20</version.com.fasterxml.jackson.annotations>
@@ -170,7 +172,7 @@
170172
<artifactId>serverlessworkflow-types</artifactId>
171173
<version>${project.version}</version>
172174
</dependency>
173-
<dependency>
175+
<dependency>
174176
<groupId>io.serverlessworkflow</groupId>
175177
<artifactId>serverlessworkflow-serialization</artifactId>
176178
<version>${project.version}</version>
@@ -250,9 +252,15 @@
250252
<scope>test</scope>
251253
</dependency>
252254
<dependency>
253-
<groupId>dev.langchain4j</groupId>
254-
<artifactId>langchain4j-agentic</artifactId>
255-
<version>${version.dev.langchain4j.beta}</version>
255+
<groupId>org.awaitility</groupId>
256+
<artifactId>awaitility</artifactId>
257+
<version>${version.awaitility}</version>
258+
<scope>test</scope>
259+
</dependency>
260+
<dependency>
261+
<groupId>dev.langchain4j</groupId>
262+
<artifactId>langchain4j-agentic</artifactId>
263+
<version>${version.dev.langchain4j.beta}</version>
256264
</dependency>
257265
</dependencies>
258266
</dependencyManagement>
@@ -304,8 +312,8 @@
304312
<module name="Checker">
305313
<module name="TreeWalker">
306314
<module name="RegexpSinglelineJava">
307-
<property name="format" value="@author" />
308-
<property name="message" value="No @author tag allowed" />
315+
<property name="format" value="@author"/>
316+
<property name="message" value="No @author tag allowed"/>
309317
</module>
310318
</module>
311319
</module>
@@ -338,7 +346,7 @@
338346
<configuration>
339347
<java>
340348
<!-- formatter -->
341-
<googleJavaFormat version="1.17.0" />
349+
<googleJavaFormat version="1.17.0"/>
342350
<!-- add/normalize headers -->
343351
<licenseHeader>
344352
<content>

0 commit comments

Comments
 (0)