From e4f04bfc3f7e9f9ce54422453961bd79b15f4681 Mon Sep 17 00:00:00 2001 From: Francisco Javier Tirado Sarti Date: Mon, 16 Dec 2024 15:47:58 +0100 Subject: [PATCH] Fix http flaky test The pet API might randomly return a 404. Signed-off-by: Francisco Javier Tirado Sarti --- .../impl/HTTPWorkflowDefinitionTest.java | 8 +++++-- .../call-http-endpoint-interpolation.yaml | 21 ++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/impl/http/src/test/java/io/serverlessworkflow/impl/HTTPWorkflowDefinitionTest.java b/impl/http/src/test/java/io/serverlessworkflow/impl/HTTPWorkflowDefinitionTest.java index d9d2663a..c6447141 100644 --- a/impl/http/src/test/java/io/serverlessworkflow/impl/HTTPWorkflowDefinitionTest.java +++ b/impl/http/src/test/java/io/serverlessworkflow/impl/HTTPWorkflowDefinitionTest.java @@ -62,12 +62,16 @@ void testWrongSchema(String fileName) { .hasMessageContaining("There are JsonSchema validation errors"); } + private static boolean httpCondition(Object obj) { + Map map = (Map) obj; + return map.containsKey("photoUrls") || map.containsKey("petId"); + } + private static Stream provideParameters() { Map petInput = Map.of("petId", 10); Map starTrekInput = Map.of("uid", "MOMA0000092393"); Condition petCondition = - new Condition<>( - o -> ((Map) o).containsKey("photoUrls"), "callHttpCondition"); + new Condition<>(HTTPWorkflowDefinitionTest::httpCondition, "callHttpCondition"); Condition starTrekCondition = new Condition<>( o -> diff --git a/impl/http/src/test/resources/call-http-endpoint-interpolation.yaml b/impl/http/src/test/resources/call-http-endpoint-interpolation.yaml index 5c1239f0..43ba4988 100644 --- a/impl/http/src/test/resources/call-http-endpoint-interpolation.yaml +++ b/impl/http/src/test/resources/call-http-endpoint-interpolation.yaml @@ -4,10 +4,17 @@ document: name: call-http-shorthand-endpoint version: '0.1.0' do: - - getPet: - call: http - with: - headers: - content-type: application/json - method: get - endpoint: ${ "https://petstore.swagger.io/v2/pet/\(.petId)" } \ No newline at end of file + - tryGetPet: + try: + - getPet: + call: http + with: + headers: + content-type: application/json + method: get + endpoint: ${ "https://petstore.swagger.io/v2/pet/\(.petId)" } + catch: + errors: + with: + type: https://serverlessworkflow.io/spec/1.0.0/errors/communication + status: 404 \ No newline at end of file