Skip to content

Commit

Permalink
Use port 0 when starting a websocket server in tests (PegaSysEng#1416)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajsutton authored and notlesh committed May 14, 2019
1 parent 8c414f8 commit 25242c5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
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

0 comments on commit 25242c5

Please sign in to comment.