Skip to content

Commit

Permalink
Merge pull request #624 from axonivy-market/hardenFlakyAsync
Browse files Browse the repository at this point in the history
harden flacky test: assert graceful up to 10 seconds for the async
  • Loading branch information
ivy-rew authored Nov 12, 2024
2 parents 11feb80 + 547577d commit f137672
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<List<String>> 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")
);
}

}

0 comments on commit f137672

Please sign in to comment.