From 35e71eab1523b4d8cc5e0c5bd97eca2334508778 Mon Sep 17 00:00:00 2001 From: "J. Koster" Date: Thu, 17 Oct 2024 08:46:50 +0200 Subject: [PATCH] STNG-8 Improve running speed of auto tests and manual tests (#197) --- .../springboot/ConformanceApplication.java | 2 +- .../conformance/manual/ManualTestBase.java | 23 ++++++++++--------- .../ConformanceApplicationTest.java | 4 ++-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/spring-boot/src/main/java/org/dcsa/conformance/springboot/ConformanceApplication.java b/spring-boot/src/main/java/org/dcsa/conformance/springboot/ConformanceApplication.java index 2a84124b..eb258c02 100644 --- a/spring-boot/src/main/java/org/dcsa/conformance/springboot/ConformanceApplication.java +++ b/spring-boot/src/main/java/org/dcsa/conformance/springboot/ConformanceApplication.java @@ -161,7 +161,7 @@ public ConformanceApplication(ConformanceConfiguration conformanceConfiguration) log.error("Deferred sandbox task execution failed", e); } }, - 100, + 5, TimeUnit.MILLISECONDS); Stream componentFactories = diff --git a/spring-boot/src/test/java/org/dcsa/conformance/manual/ManualTestBase.java b/spring-boot/src/test/java/org/dcsa/conformance/manual/ManualTestBase.java index 1d993239..b6f492b9 100644 --- a/spring-boot/src/test/java/org/dcsa/conformance/manual/ManualTestBase.java +++ b/spring-boot/src/test/java/org/dcsa/conformance/manual/ManualTestBase.java @@ -75,7 +75,7 @@ void startOrStopScenario(SandboxConfig sandbox, String scenarioId) { assertTrue(webuiHandler.handleRequest(USER_ID, node).isEmpty()); } - void notifyAction(SandboxConfig sandbox) { + void notifyAction(SandboxConfig sandbox, SandboxConfig otherSandbox) { log.debug("Notifying party."); ObjectNode node = mapper @@ -83,8 +83,9 @@ void notifyAction(SandboxConfig sandbox) { .put("operation", "notifyParty") .put("sandboxId", sandbox.sandboxId); assertTrue(webuiHandler.handleRequest(USER_ID, node).isEmpty()); + waitForAsyncCalls(50L); waitForCleanSandboxStatus(sandbox); - waitForAsyncCalls(250L); + waitForCleanSandboxStatus(otherSandbox); } void completeAction(SandboxConfig sandbox) { @@ -100,6 +101,7 @@ void completeAction(SandboxConfig sandbox) { } void validateSandboxScenarioGroup(SandboxConfig sandbox1, String scenarioId, String scenarioName) { + waitForCleanSandboxStatus(sandbox1); log.info("Validating scenario '{}'.", scenarioName); JsonNode jsonNode = getScenarioStatus(sandbox1, scenarioId); assertTrue(jsonNode.has("isRunning"), "Did scenarioId '" + scenarioId + "' run? Can't find it's state. "); @@ -169,12 +171,12 @@ void waitForCleanSandboxStatus(SandboxConfig sandbox) { sandboxStatus = webuiHandler.handleRequest(USER_ID, node).toString(); if (sandboxStatus.contains("[]")) return; counter++; - waitForAsyncCalls(300L); // Wait for the scenario to finish - } while (counter < 30); + waitForAsyncCalls(20L); // Wait for the scenario to finish + } while (counter < 1000); log.warn( "Waited for {} ms for sandbox status to reach the expected state: {}", - counter * 300, + counter * 20, sandboxStatus); throw new RuntimeException( "Sandbox status did not reach the expected state on time: " + sandboxStatus); @@ -301,8 +303,7 @@ void runScenario( SandboxConfig sandbox1, SandboxConfig sandbox2, String scenarioId, String scenarioName) { log.debug("Starting scenario '{}'.", scenarioName); startOrStopScenario(sandbox1, scenarioId); - notifyAction(sandbox2); - waitForCleanSandboxStatus(sandbox1); + notifyAction(sandbox2, sandbox1); boolean isRunning; do { @@ -319,7 +320,7 @@ void runScenario( // Special flow for: eBL TD-only UC6 in Carrier mode (DT-1681) if (jsonForPromptText.contains("Insert TDR here")) { - jsonForPrompt = fetchTransportDocument(sandbox2); + jsonForPrompt = fetchTransportDocument(sandbox2, sandbox1); } handleActionInput(sandbox1, scenarioId, promptActionId, jsonForPrompt); @@ -331,15 +332,15 @@ void runScenario( fail(); } if (hasPromptText && !jsonNode.get("promptText").textValue().isEmpty()) { - notifyAction(sandbox2); + notifyAction(sandbox2, sandbox1); } if (isRunning) completeAction(sandbox1); } while (isRunning); validateSandboxScenarioGroup(sandbox1, scenarioId, scenarioName); } - private JsonNode fetchTransportDocument(SandboxConfig sandbox2) { - notifyAction(sandbox2); + private JsonNode fetchTransportDocument(SandboxConfig sandbox2, SandboxConfig sandbox1) { + notifyAction(sandbox2, sandbox1); log.debug("Fetching transport document reference from sandbox2"); String referenceText = diff --git a/spring-boot/src/test/java/org/dcsa/conformance/springboot/ConformanceApplicationTest.java b/spring-boot/src/test/java/org/dcsa/conformance/springboot/ConformanceApplicationTest.java index 0c1dd7b0..389e5b25 100644 --- a/spring-boot/src/test/java/org/dcsa/conformance/springboot/ConformanceApplicationTest.java +++ b/spring-boot/src/test/java/org/dcsa/conformance/springboot/ConformanceApplicationTest.java @@ -73,7 +73,7 @@ private void checkUntilScenariosAreReady(String sandboxId) throws InterruptedExc String previousStatus = ""; String startStatus = restTemplate.getForObject("http://localhost:" + port + getAppURL(sandboxId, "status"), String.class); do { - Thread.sleep(3_000L); + Thread.sleep(500L); status = restTemplate.getForObject("http://localhost:" + port + getAppURL(sandboxId, "status"), String.class); if (status.equals(previousStatus)) { // Detection of a stuck scenario, prevent waiting forever. Note: turn off while debugging! log.error("Status did not change: {}. Originally started at: {}", status, startStatus); @@ -82,7 +82,7 @@ private void checkUntilScenariosAreReady(String sandboxId) throws InterruptedExc log.info("Current status: {}", status); previousStatus = status; if (status.length() > "{\"scenariosLeft\":0}".length()) { // More than 9 scenarios left, wait longer - Thread.sleep(7_000L); + Thread.sleep(1_000L); } } while (!status.equals("{\"scenariosLeft\":0}")); stopWatch.stop();