Fixed checking of server already running
This commit is contained in:
parent
0982bd982c
commit
bf52e7a992
@ -13,7 +13,7 @@ import org.owasp.webwolf.WebWolf;
|
|||||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.ServerSocket;
|
import java.net.Socket;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -43,10 +43,12 @@ public abstract class IntegrationTest {
|
|||||||
public static void beforeAll() {
|
public static void beforeAll() {
|
||||||
if (!started) {
|
if (!started) {
|
||||||
started = true;
|
started = true;
|
||||||
if (!isAlreadyRunning()) {
|
if (!isAlreadyRunning(WG_PORT)) {
|
||||||
SpringApplicationBuilder wgs = new SpringApplicationBuilder(StartWebGoat.class)
|
SpringApplicationBuilder wgs = new SpringApplicationBuilder(StartWebGoat.class)
|
||||||
.properties(Map.of("spring.config.name", "application-webgoat", "WEBGOAT_PORT", WG_PORT));
|
.properties(Map.of("spring.config.name", "application-webgoat", "WEBGOAT_PORT", WG_PORT));
|
||||||
wgs.run();
|
wgs.run();
|
||||||
|
}
|
||||||
|
if (!isAlreadyRunning(WW_PORT)) {
|
||||||
SpringApplicationBuilder wws = new SpringApplicationBuilder(WebWolf.class)
|
SpringApplicationBuilder wws = new SpringApplicationBuilder(WebWolf.class)
|
||||||
.properties(Map.of("spring.config.name", "application-webwolf", "WEBWOLF_PORT", WW_PORT));
|
.properties(Map.of("spring.config.name", "application-webwolf", "WEBWOLF_PORT", WW_PORT));
|
||||||
wws.run();
|
wws.run();
|
||||||
@ -54,11 +56,11 @@ public abstract class IntegrationTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isAlreadyRunning() {
|
private static boolean isAlreadyRunning(int port) {
|
||||||
try (var ignored = new ServerSocket(WG_PORT)) {
|
try (var ignored = new Socket("127.0.0.1", port)) {
|
||||||
return false;
|
|
||||||
} catch (IOException e) {
|
|
||||||
return true;
|
return true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user