mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-02-21 12:46:10 +00:00
Dont reuse ports in tests
This commit is contained in:
parent
f91977cbac
commit
8dbcd29c8d
@ -21,12 +21,14 @@ package ca.uhn.fhir.util;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides server ports
|
* Provides server ports
|
||||||
*/
|
*/
|
||||||
@CoverageIgnore
|
@CoverageIgnore
|
||||||
public class PortUtil {
|
public class PortUtil {
|
||||||
|
private static LinkedHashSet<Integer> ourPorts = new LinkedHashSet<>();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Non instantiable
|
* Non instantiable
|
||||||
@ -41,9 +43,13 @@ public class PortUtil {
|
|||||||
public static int findFreePort() {
|
public static int findFreePort() {
|
||||||
ServerSocket server;
|
ServerSocket server;
|
||||||
try {
|
try {
|
||||||
|
int port;
|
||||||
|
do {
|
||||||
server = new ServerSocket(0);
|
server = new ServerSocket(0);
|
||||||
int port = server.getLocalPort();
|
port = server.getLocalPort();
|
||||||
server.close();
|
server.close();
|
||||||
|
} while (!ourPorts.add(port));
|
||||||
|
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
return port;
|
return port;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user