Skip to content

Commit 94f1a4e

Browse files
committed
Closes #620: remove Thread.sleep from integration tests
replace all Thread.sleep calls with better Awaitility.await
1 parent 1e48fcc commit 94f1a4e

29 files changed

+1344
-1078
lines changed

taskana-adapter-camunda-spring-boot-test/pom.xml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@
119119
<artifactId>taskana-adapter-camunda-outbox-rest-spring-boot-starter</artifactId>
120120
<version>${project.version}</version>
121121
</dependency>
122+
<dependency>
123+
<groupId>org.awaitility</groupId>
124+
<artifactId>awaitility</artifactId>
125+
<scope>test</scope>
126+
</dependency>
122127
<dependency>
123128
<groupId>org.assertj</groupId>
124129
<artifactId>assertj-core</artifactId>
@@ -142,7 +147,24 @@
142147
<artifactId>okhttp</artifactId>
143148
<scope>test</scope>
144149
</dependency>
145-
150+
<dependency>
151+
<groupId>io.github.logrecorder</groupId>
152+
<artifactId>logrecorder-junit5</artifactId>
153+
<version>2.9.1</version>
154+
<scope>test</scope>
155+
</dependency>
156+
<dependency>
157+
<groupId>io.github.logrecorder</groupId>
158+
<artifactId>logrecorder-logback</artifactId>
159+
<version>2.9.1</version>
160+
<scope>test</scope>
161+
</dependency>
162+
<dependency>
163+
<groupId>io.github.logrecorder</groupId>
164+
<artifactId>logrecorder-assertions</artifactId>
165+
<version>2.9.1</version>
166+
<scope>test</scope>
167+
</dependency>
146168
</dependencies>
147169

148170
<build>

taskana-adapter-camunda-spring-boot-test/src/test/java/pro/taskana/adapter/integration/AbsIntegrationTest.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,19 @@ abstract class AbsIntegrationTest {
4747
@Value("${taskana.adapter.scheduler.run.interval.for.complete.referenced.tasks.in.milliseconds}")
4848
protected long adapterCompletionPollingInterval;
4949

50-
@Value(
51-
"${taskana.adapter.scheduler.run.interval.for.check.finished.referenced.tasks.in.milliseconds}")
50+
@Value("${taskana.adapter.scheduler.run.interval.for.check.finished.referenced.tasks.in.milliseconds}")
5251
protected long adapterCancelledClaimPollingInterval;
5352

5453
@Value("${taskana.adapter.scheduler.run.interval.for.claim.referenced.tasks.in.milliseconds}")
5554
protected long adapterClaimPollingInterval;
5655

57-
@Value(
58-
"${taskana.adapter.scheduler.run.interval.for.cancel.claim.referenced.tasks.in.milliseconds}")
56+
@Value("${taskana.adapter.scheduler.run.interval.for.cancel.claim.referenced.tasks.in.milliseconds}")
5957
protected long adapterCancelPollingInterval;
6058

6159
@Value("${adapter.polling.inverval.adjustment.factor}")
6260
protected double adapterPollingInvervalAdjustmentFactor;
6361

64-
@Value(
65-
"${taskana.adapter.scheduler.run.interval.for.retries.and.blocking.taskevents.in.milliseconds}")
62+
@Value("${taskana.adapter.scheduler.run.interval.for.retries.and.blocking.taskevents.in.milliseconds}")
6663
protected long adapterRetryAndBlockingInterval;
6764

6865
protected CamundaProcessengineRequester camundaProcessengineRequester;

taskana-adapter-camunda-spring-boot-test/src/test/java/pro/taskana/adapter/integration/ArchitectureTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import com.tngtech.archunit.core.importer.ClassFileImporter;
1313
import com.tngtech.archunit.core.importer.ImportOption.OnlyIncludeTests;
1414
import java.util.List;
15-
import org.junit.jupiter.api.Disabled;
1615
import org.junit.jupiter.api.Test;
1716
import org.junit.jupiter.api.TestFactory;
1817
import org.junit.jupiter.api.TestTemplate;
@@ -65,7 +64,6 @@ void testClassesAndTestMethodsShouldBePackagePrivate() {
6564
.check(IMPORTED_TEST_CLASSES);
6665
}
6766

68-
@Disabled("so long disabled until all tests using awaitibility")
6967
@Test
7068
void noMethodsShouldUseThreadSleep() {
7169
noClasses()

taskana-adapter-camunda-spring-boot-test/src/test/java/pro/taskana/adapter/integration/CamundaProcessengineRequester.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,14 +210,10 @@ public boolean isCorrectAssigneeFromHistory(String camundaTaskId, String assigne
210210
restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class);
211211
// no task found will only show in empty body
212212
JSONArray taskHistoryRetrievalAnswerJson = new JSONArray(response.getBody());
213-
if (taskHistoryRetrievalAnswerJson.length() == 0) {
214-
return false;
215-
} else {
216-
String camundaTaskAssignee =
217-
(String) ((JSONObject) taskHistoryRetrievalAnswerJson.get(0)).get("assignee");
218-
if (assignee.equals(camundaTaskAssignee)) {
219-
return true;
220-
}
213+
if (!taskHistoryRetrievalAnswerJson.isEmpty()) {
214+
JSONObject jsonObject = (JSONObject) taskHistoryRetrievalAnswerJson.get(0);
215+
Object jsonObjectAssignee = jsonObject.get("assignee");
216+
return assignee.equals(jsonObjectAssignee);
221217
}
222218
return false;
223219
}

taskana-adapter-camunda-spring-boot-test/src/test/java/pro/taskana/adapter/integration/CamundaTaskEventErrorHandlerTest.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package pro.taskana.adapter.integration;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.awaitility.Awaitility.await;
5+
import static org.awaitility.Durations.ONE_HUNDRED_MILLISECONDS;
6+
import static org.awaitility.Durations.ONE_SECOND;
7+
import static org.awaitility.Durations.TWO_HUNDRED_MILLISECONDS;
48

59
import org.apache.commons.lang3.StringUtils;
10+
import org.hamcrest.Matchers;
611
import org.json.JSONArray;
712
import org.json.JSONObject;
813
import org.junit.jupiter.api.AfterEach;
@@ -76,12 +81,14 @@ void should_CreateErrorLogWithOneCause_When_ExceptionWithOneCauseOccurred() {
7681
connector.taskanaTaskFailedToBeCreatedForNewReferencedTask(
7782
referencedTask, testException)));
7883

79-
try {
80-
Thread.sleep(100);
81-
} catch (InterruptedException e) {
82-
e.printStackTrace();
83-
}
84-
CamundaTaskEvent camundaTaskEvent = taskanaOutboxRequester.getAllEvents().get(0);
84+
CamundaTaskEvent camundaTaskEvent = await()
85+
.atMost(ONE_SECOND)
86+
.with()
87+
.pollInterval(ONE_HUNDRED_MILLISECONDS)
88+
.pollDelay(TWO_HUNDRED_MILLISECONDS)
89+
.until(
90+
() -> taskanaOutboxRequester.getAllEvents(),
91+
Matchers.hasSize(1)).get(0);
8592
JSONObject errorJson = new JSONObject(camundaTaskEvent.getError());
8693

8794
assertThat(errorJson).hasToString(expectedErrorJson.toString());

0 commit comments

Comments
 (0)