Skip to content

Commit

Permalink
STNG-8 Improve running speed of auto tests and manual tests (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkosternl authored Oct 17, 2024
1 parent c50d759 commit 35e71ea
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public ConformanceApplication(ConformanceConfiguration conformanceConfiguration)
log.error("Deferred sandbox task execution failed", e);
}
},
100,
5,
TimeUnit.MILLISECONDS);

Stream<AbstractComponentFactory> componentFactories =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,17 @@ 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
.createObjectNode()
.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) {
Expand All @@ -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. ");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
Expand Down

0 comments on commit 35e71ea

Please sign in to comment.