Skip to content

Commit 2647a7f

Browse files
committed
Add timeout to test
1 parent a1a9ce6 commit 2647a7f

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/test/java/com/iexec/core/worker/WorkerServiceRealRepositoryTests.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.iexec.core.configuration.WorkerConfiguration;
2020
import lombok.extern.slf4j.Slf4j;
2121
import org.assertj.core.api.Assertions;
22+
import org.awaitility.Awaitility;
2223
import org.junit.jupiter.api.BeforeEach;
2324
import org.junit.jupiter.api.Test;
2425
import org.mockito.Mock;
@@ -32,13 +33,11 @@
3233
import org.testcontainers.junit.jupiter.Testcontainers;
3334
import org.testcontainers.utility.DockerImageName;
3435

36+
import java.time.Duration;
3537
import java.util.Date;
3638
import java.util.List;
3739
import java.util.Optional;
38-
import java.util.concurrent.ExecutionException;
39-
import java.util.concurrent.ExecutorService;
40-
import java.util.concurrent.Executors;
41-
import java.util.concurrent.Future;
40+
import java.util.concurrent.*;
4241
import java.util.stream.Collectors;
4342
import java.util.stream.IntStream;
4443

@@ -74,7 +73,7 @@ void init() {
7473
* If everything goes right, the Worker should finally have been assigned N tasks.
7574
*/
7675
@Test
77-
void addMultipleTaskIds() throws ExecutionException, InterruptedException {
76+
void addMultipleTaskIds() {
7877
workerService.addWorker(
7978
Worker.builder()
8079
.walletAddress(WALLET_WORKER_1)
@@ -88,9 +87,9 @@ void addMultipleTaskIds() throws ExecutionException, InterruptedException {
8887
.mapToObj(i -> executor.submit(() -> workerService.addChainTaskIdToWorker(new Date().getTime() + "", WALLET_WORKER_1)))
8988
.collect(Collectors.toList());
9089

91-
for (Future<Optional<Worker>> future : futures) {
92-
future.get();
93-
}
90+
Awaitility.await()
91+
.atMost(Duration.ofMinutes(1))
92+
.until(() -> futures.stream().map(Future::isDone).reduce(Boolean::logicalAnd).orElse(false));
9493

9594
Assertions.assertThat(workerService.getWorker(WALLET_WORKER_1).get().getComputingChainTaskIds())
9695
.hasSize(nThreads);

0 commit comments

Comments
 (0)