Use port 0 when starting a websocket server in tests (#1416)

Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
This commit is contained in:
Adrian Sutton
2019-05-08 17:31:45 +10:00
committed by GitHub
parent bdef585941
commit 710db6d1fa
2 changed files with 9 additions and 2 deletions

View File

@@ -266,6 +266,8 @@ public class JsonRpcHttpServiceRpcApisTest {
final Set<Capability> supportedCapabilities = new HashSet<>();
supportedCapabilities.add(EthProtocol.ETH62);
supportedCapabilities.add(EthProtocol.ETH63);
jsonRpcConfiguration.setPort(0);
webSocketConfiguration.setPort(0);
final Map<String, JsonRpcMethod> rpcMethods =
spy(

View File

@@ -20,6 +20,7 @@ import tech.pegasys.pantheon.ethereum.jsonrpc.internal.methods.JsonRpcMethod;
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.methods.WebSocketMethodsFactory;
import tech.pegasys.pantheon.ethereum.jsonrpc.websocket.subscription.SubscriptionManager;
import java.net.InetSocketAddress;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -56,9 +57,11 @@ public class WebSocketHostWhitelistTest {
private WebSocketService websocketService;
private HttpClient httpClient;
private static final int VERTX_AWAIT_TIMEOUT_MILLIS = 10000;
private int websocketPort;
@Before
public void initServerAndClient() {
webSocketConfiguration.setPort(0);
vertx = Vertx.vertx();
final Map<String, JsonRpcMethod> websocketMethods =
@@ -68,11 +71,13 @@ public class WebSocketHostWhitelistTest {
websocketService =
new WebSocketService(vertx, webSocketConfiguration, webSocketRequestHandlerSpy);
websocketService.start().join();
final InetSocketAddress inetSocketAddress = websocketService.socketAddress();
websocketPort = inetSocketAddress.getPort();
final HttpClientOptions httpClientOptions =
new HttpClientOptions()
.setDefaultHost(webSocketConfiguration.getHost())
.setDefaultPort(webSocketConfiguration.getPort());
.setDefaultPort(websocketPort);
httpClient = vertx.createHttpClient(httpClientOptions);
}
@@ -171,7 +176,7 @@ public class WebSocketHostWhitelistTest {
final HttpClientRequest request =
httpClient.post(
webSocketConfiguration.getPort(),
websocketPort,
webSocketConfiguration.getHost(),
"/",
response -> {