From 547577d352c455976c2e1690fa9e6dad069c6624 Mon Sep 17 00:00:00 2001 From: Reguel Wermelinger Date: Mon, 11 Nov 2024 09:42:37 +0100 Subject: [PATCH] harden flacky test: assert graceful up to 10 seconds for the async available result --- .../rest/bpm/TestAsyncInvocation.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/connectivity/connectivity-demos-test/src_test/rest/bpm/TestAsyncInvocation.java b/connectivity/connectivity-demos-test/src_test/rest/bpm/TestAsyncInvocation.java index e9accb3e3..958ab9b67 100644 --- a/connectivity/connectivity-demos-test/src_test/rest/bpm/TestAsyncInvocation.java +++ b/connectivity/connectivity-demos-test/src_test/rest/bpm/TestAsyncInvocation.java @@ -3,14 +3,22 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; +import org.awaitility.Awaitility; import org.junit.jupiter.api.Test; + import ch.ivyteam.ivy.bpm.engine.client.BpmClient; import ch.ivyteam.ivy.bpm.engine.client.ExecutionResult; import ch.ivyteam.ivy.bpm.exec.client.IvyProcessTest; import ch.ivyteam.ivy.environment.Ivy; +import ch.ivyteam.ivy.process.model.value.SignalCode; import ch.ivyteam.ivy.workflow.query.SignalEventQuery; +import ch.ivyteam.ivy.workflow.signal.ISignalEvent; @IvyProcessTest(enableWebServer = true) public class TestAsyncInvocation @@ -22,12 +30,17 @@ void callBatchAsync(BpmClient bpmClient) throws InterruptedException ExecutionResult result = bpmClient.start().process("rest/asyncInvocation/callBatchAsync.ivp").execute(); assertThat(result).isNotNull(); - Thread.sleep(4000); - SignalEventQuery query = Ivy.wf().signals().history() - .createSignalEventQuery(); - var fired = new ArrayList<>(query.executor().results()); - assertThat(fired).isNotEmpty(); - assertThat(fired.get(0).getSignalCode().toString()).isEqualTo("rest:batch:result:ok"); + SignalEventQuery query = Ivy.wf().signals().history().createSignalEventQuery(); + + Supplier> signals = () -> new ArrayList<>(query.executor().results()) + .stream().map(ISignalEvent::getSignalCode).map(SignalCode::toString) + .toList(); + Awaitility.await() + .atLeast(3, TimeUnit.SECONDS) // default delay: on process being called + .atMost(10, TimeUnit.SECONDS) + .until(() -> signals.get(), + codes -> !codes.isEmpty() && Objects.equals(codes.get(0), "rest:batch:result:ok") + ); } }