Skip to content

Commit

Permalink
Retry starting the server in case it took some time to shut down afte…
Browse files Browse the repository at this point in the history
…r the previous test run
  • Loading branch information
ohadzeliger committed Jan 23, 2025
1 parent 1dd4539 commit 897bcbc
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ public void beforeAll(ExtensionContext context) throws Exception {
processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);

this.serverProcess = processBuilder.start();

// TODO: There should be a better way to figure out that the server is fully up and running
Thread.sleep(3000);
if (!serverProcess.isAlive()) {
if (!startServer(processBuilder)) {
Assertions.fail("Failed to start the external server");
}

Expand Down Expand Up @@ -133,4 +129,22 @@ public void afterAll(ExtensionContext context) throws Exception {
}
}

private boolean startServer(ProcessBuilder processBuilder) throws IOException, InterruptedException {
try {
serverProcess = processBuilder.start();
// TODO: There should be a better way to figure out that the server is fully up and running
Thread.sleep(3000);
if (!serverProcess.isAlive()) {
throw new Exception("Failed to start server once - retrying");
}
return true;
} catch (Exception ex) {
// Try once more
serverProcess = processBuilder.start();
// TODO: There should be a better way to figure out that the server is fully up and running
Thread.sleep(3000);
}

return serverProcess.isAlive();
}
}

0 comments on commit 897bcbc

Please sign in to comment.