1919import com .iexec .core .configuration .WorkerConfiguration ;
2020import lombok .extern .slf4j .Slf4j ;
2121import org .assertj .core .api .Assertions ;
22+ import org .awaitility .Awaitility ;
2223import org .junit .jupiter .api .BeforeEach ;
2324import org .junit .jupiter .api .Test ;
2425import org .mockito .Mock ;
3233import org .testcontainers .junit .jupiter .Testcontainers ;
3334import org .testcontainers .utility .DockerImageName ;
3435
36+ import java .time .Duration ;
3537import java .util .Date ;
3638import java .util .List ;
3739import 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 .*;
4241import java .util .stream .Collectors ;
4342import 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