Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

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

Merged
merged 3 commits into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ private JsonRpcHttpService createJsonRpcHttpService(
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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;
Expand Down Expand Up @@ -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 =
Expand All @@ -68,11 +71,13 @@ public void initServerAndClient() {
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);
}
Expand Down Expand Up @@ -171,7 +176,7 @@ private void doHttpRequestAndVerify(

final HttpClientRequest request =
httpClient.post(
webSocketConfiguration.getPort(),
websocketPort,
webSocketConfiguration.getHost(),
"/",
response -> {
Expand Down