Skip to content

Commit

Permalink
Closes Taskana#620: remove Thread.sleep from integration tests
Browse files Browse the repository at this point in the history
replace all Thread.sleep calls with better Awaitility.await
  • Loading branch information
arolfes committed Nov 24, 2023
1 parent a2ac27c commit a2cf5c2
Show file tree
Hide file tree
Showing 29 changed files with 1,344 additions and 1,078 deletions.
24 changes: 23 additions & 1 deletion taskana-adapter-camunda-spring-boot-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@
<artifactId>taskana-adapter-camunda-outbox-rest-spring-boot-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand All @@ -142,7 +147,24 @@
<artifactId>okhttp</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.github.logrecorder</groupId>
<artifactId>logrecorder-junit5</artifactId>
<version>2.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.logrecorder</groupId>
<artifactId>logrecorder-logback</artifactId>
<version>2.9.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.logrecorder</groupId>
<artifactId>logrecorder-assertions</artifactId>
<version>2.9.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,19 @@ abstract class AbsIntegrationTest {
@Value("${taskana.adapter.scheduler.run.interval.for.complete.referenced.tasks.in.milliseconds}")
protected long adapterCompletionPollingInterval;

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

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

@Value(
"${taskana.adapter.scheduler.run.interval.for.cancel.claim.referenced.tasks.in.milliseconds}")
@Value("${taskana.adapter.scheduler.run.interval.for.cancel.claim.referenced.tasks.in.milliseconds}")
protected long adapterCancelPollingInterval;

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

@Value(
"${taskana.adapter.scheduler.run.interval.for.retries.and.blocking.taskevents.in.milliseconds}")
@Value("${taskana.adapter.scheduler.run.interval.for.retries.and.blocking.taskevents.in.milliseconds}")
protected long adapterRetryAndBlockingInterval;

protected CamundaProcessengineRequester camundaProcessengineRequester;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.tngtech.archunit.core.importer.ClassFileImporter;
import com.tngtech.archunit.core.importer.ImportOption.OnlyIncludeTests;
import java.util.List;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.api.TestTemplate;
Expand Down Expand Up @@ -65,7 +64,6 @@ void testClassesAndTestMethodsShouldBePackagePrivate() {
.check(IMPORTED_TEST_CLASSES);
}

@Disabled("so long disabled until all tests using awaitibility")
@Test
void noMethodsShouldUseThreadSleep() {
noClasses()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,10 @@ public boolean isCorrectAssigneeFromHistory(String camundaTaskId, String assigne
restTemplate.exchange(url, HttpMethod.GET, requestEntity, String.class);
// no task found will only show in empty body
JSONArray taskHistoryRetrievalAnswerJson = new JSONArray(response.getBody());
if (taskHistoryRetrievalAnswerJson.length() == 0) {
return false;
} else {
String camundaTaskAssignee =
(String) ((JSONObject) taskHistoryRetrievalAnswerJson.get(0)).get("assignee");
if (assignee.equals(camundaTaskAssignee)) {
return true;
}
if (!taskHistoryRetrievalAnswerJson.isEmpty()) {
JSONObject jsonObject = (JSONObject) taskHistoryRetrievalAnswerJson.get(0);
Object jsonObjectAssignee = jsonObject.get("assignee");
return assignee.equals(jsonObjectAssignee);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package pro.taskana.adapter.integration;

import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.awaitility.Durations.ONE_HUNDRED_MILLISECONDS;
import static org.awaitility.Durations.ONE_SECOND;
import static org.awaitility.Durations.TWO_HUNDRED_MILLISECONDS;

import org.apache.commons.lang3.StringUtils;
import org.hamcrest.Matchers;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -76,12 +81,14 @@ void should_CreateErrorLogWithOneCause_When_ExceptionWithOneCauseOccurred() {
connector.taskanaTaskFailedToBeCreatedForNewReferencedTask(
referencedTask, testException)));

try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
CamundaTaskEvent camundaTaskEvent = taskanaOutboxRequester.getAllEvents().get(0);
CamundaTaskEvent camundaTaskEvent = await()
.atMost(ONE_SECOND)
.with()
.pollInterval(ONE_HUNDRED_MILLISECONDS)
.pollDelay(TWO_HUNDRED_MILLISECONDS)
.until(
() -> taskanaOutboxRequester.getAllEvents(),
Matchers.hasSize(1)).get(0);
JSONObject errorJson = new JSONObject(camundaTaskEvent.getError());

assertThat(errorJson).hasToString(expectedErrorJson.toString());
Expand Down
Loading

0 comments on commit a2cf5c2

Please sign in to comment.