Skip to content

Commit

Permalink
Fixed checking of server already running
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaars committed Sep 9, 2019
1 parent 0982bd9 commit bf52e7a
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.springframework.boot.builder.SpringApplicationBuilder;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Map;
import java.util.UUID;

Expand Down Expand Up @@ -43,22 +43,24 @@ public abstract class IntegrationTest {
public static void beforeAll() {
if (!started) {
started = true;
if (!isAlreadyRunning()) {
if (!isAlreadyRunning(WG_PORT)) {
SpringApplicationBuilder wgs = new SpringApplicationBuilder(StartWebGoat.class)
.properties(Map.of("spring.config.name", "application-webgoat", "WEBGOAT_PORT", WG_PORT));
wgs.run();
}
if (!isAlreadyRunning(WW_PORT)) {
SpringApplicationBuilder wws = new SpringApplicationBuilder(WebWolf.class)
.properties(Map.of("spring.config.name", "application-webwolf", "WEBWOLF_PORT", WW_PORT));
wws.run();
}
}
}

private static boolean isAlreadyRunning() {
try (var ignored = new ServerSocket(WG_PORT)) {
return false;
} catch (IOException e) {
private static boolean isAlreadyRunning(int port) {
try (var ignored = new Socket("127.0.0.1", port)) {
return true;
} catch (IOException e) {
return false;
}
}

Expand Down

0 comments on commit bf52e7a

Please sign in to comment.