From 126e30b0e93b4858d6dd04408df6eec92e65b59d Mon Sep 17 00:00:00 2001 From: Lucas Saldanha Date: Thu, 22 Nov 2018 09:55:43 +1300 Subject: [PATCH] Enabling previously ignored acceptance tests (#282) --- Jenkinsfile | 2 +- .../CreateAccountAcceptanceTest.java | 2 - .../RpcApisTogglesAcceptanceTest.java | 14 +++--- .../acceptance/dsl/node/PantheonNode.java | 49 +++++++++++++++++++ .../mining/MiningAcceptanceTest.java | 2 - .../NewPendingTransactionAcceptanceTest.java | 5 +- .../web3j/EventEmitterAcceptanceTest.java | 2 - 7 files changed, 62 insertions(+), 14 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 413fe72c38..9120ca3534 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -44,7 +44,7 @@ stage('Pantheon tests') { sh './gradlew --no-daemon --parallel integrationTest' } stage('Acceptance Tests') { - sh './gradlew --no-daemon --parallel acceptanceTest --tests Web3Sha3AcceptanceTest --tests PantheonClusterAcceptanceTest --tests MiningAcceptanceTest' + sh './gradlew --no-daemon --parallel acceptanceTest' } stage('Check Licenses') { sh './gradlew --no-daemon --parallel checkLicenses' diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/CreateAccountAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/CreateAccountAcceptanceTest.java index 11627e5a13..c38f81d59a 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/CreateAccountAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/CreateAccountAcceptanceTest.java @@ -19,10 +19,8 @@ import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account; import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; -@Ignore public class CreateAccountAcceptanceTest extends AcceptanceTestBase { private Node minerNode; diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/RpcApisTogglesAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/RpcApisTogglesAcceptanceTest.java index 175795c50b..8d90017a46 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/RpcApisTogglesAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/RpcApisTogglesAcceptanceTest.java @@ -12,16 +12,17 @@ */ package tech.pegasys.pantheon.tests.acceptance; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; + import tech.pegasys.pantheon.ethereum.jsonrpc.RpcApis; import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase; import tech.pegasys.pantheon.tests.acceptance.dsl.node.PantheonNode; import org.java_websocket.exceptions.WebsocketNotConnectedException; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; -@Ignore public class RpcApisTogglesAcceptanceTest extends AcceptanceTestBase { private PantheonNode rpcEnabledNode; @@ -52,15 +53,16 @@ public class RpcApisTogglesAcceptanceTest extends AcceptanceTestBase { public void shouldSucceedConnectingToNodeWithWsRpcEnabled() { rpcEnabledNode.useWebSocketsForJsonRpc(); - // TODO previously this test was calling netVersion using the HTTP not WebSockets, now failing rpcEnabledNode.verify(net.netVersion()); } @Test public void shouldFailConnectingToNodeWithWsRpcDisabled() { - rpcDisabledNode.useWebSocketsForJsonRpc(); - - rpcDisabledNode.verify(net.netVersionExceptional(WebsocketNotConnectedException.class)); + rpcDisabledNode.verify( + node -> { + final Throwable thrown = catchThrowable(() -> rpcDisabledNode.useWebSocketsForJsonRpc()); + assertThat(thrown).isInstanceOf(WebsocketNotConnectedException.class); + }); } @Test diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java index 5c61e214a2..88e80a7301 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/dsl/node/PantheonNode.java @@ -25,20 +25,28 @@ import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.Transaction; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.net.ConnectException; +import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.Properties; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import com.google.common.base.MoreObjects; import com.google.common.io.MoreFiles; import com.google.common.io.RecursiveDeleteOption; import org.apache.logging.log4j.Logger; +import org.awaitility.Awaitility; +import org.awaitility.core.ConditionTimeoutException; +import org.java_websocket.exceptions.WebsocketNotConnectedException; import org.web3j.protocol.Web3j; import org.web3j.protocol.http.HttpService; +import org.web3j.protocol.websocket.WebSocketClient; +import org.web3j.protocol.websocket.WebSocketListener; import org.web3j.protocol.websocket.WebSocketService; import org.web3j.utils.Async; @@ -150,7 +158,14 @@ public class PantheonNode implements Node, NodeConfiguration, RunnableNode, Auto public void useWebSocketsForJsonRpc() { final String url = wsRpcBaseUrl().isPresent() ? wsRpcBaseUrl().get() : "ws://127.0.0.1:8546"; + checkIfWebSocketEndpointIsAvailable(url); + final WebSocketService webSocketService = new WebSocketService(url, true); + try { + webSocketService.connect(); + } catch (ConnectException e) { + throw new RuntimeException("Error connection to WebSocket endpoint", e); + } if (web3j != null) { web3j.shutdown(); @@ -159,6 +174,40 @@ public class PantheonNode implements Node, NodeConfiguration, RunnableNode, Auto web3j = Web3j.build(webSocketService, 2000, Async.defaultExecutorService()); } + private void checkIfWebSocketEndpointIsAvailable(final String url) { + WebSocketClient webSocketClient = new WebSocketClient(URI.create(url)); + // Web3j implementation always invoke the listener (even when one hasn't been set). We are using + // this stub implementation to avoid a NullPointerException. + webSocketClient.setListener( + new WebSocketListener() { + @Override + public void onMessage(final String message) { + // DO NOTHING + } + + @Override + public void onError(final Exception e) { + // DO NOTHING + } + + @Override + public void onClose() { + // DO NOTHING + } + }); + + // Because we can't trust the connection timeout of the WebSocket client implementation, we are + // using this approach to verify if the endpoint is enabled. + webSocketClient.connect(); + try { + Awaitility.await().atMost(5, TimeUnit.SECONDS).until(webSocketClient::isOpen); + } catch (ConditionTimeoutException e) { + throw new WebsocketNotConnectedException(); + } finally { + webSocketClient.close(); + } + } + @Override public void start(final PantheonNodeRunner runner) { runner.startNode(this); diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/mining/MiningAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/mining/MiningAcceptanceTest.java index e295611a0a..08a0c03d74 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/mining/MiningAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/mining/MiningAcceptanceTest.java @@ -17,10 +17,8 @@ import tech.pegasys.pantheon.tests.acceptance.dsl.account.Account; import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; -@Ignore public class MiningAcceptanceTest extends AcceptanceTestBase { private Node minerNode; diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/pubsub/NewPendingTransactionAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/pubsub/NewPendingTransactionAcceptanceTest.java index bce461f446..a76dcebe0a 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/pubsub/NewPendingTransactionAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/acceptance/pubsub/NewPendingTransactionAcceptanceTest.java @@ -26,7 +26,6 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; -@Ignore public class NewPendingTransactionAcceptanceTest extends AcceptanceTestBase { private Vertx vertx; @@ -52,7 +51,11 @@ public class NewPendingTransactionAcceptanceTest extends AcceptanceTestBase { vertx.close(); } + /* + This test will be fixed on NC-1952 + */ @Test + @Ignore public void transactionRemovedByChainReorganisationMustPublishEvent() throws Exception { // Create the light fork diff --git a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/EventEmitterAcceptanceTest.java b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/EventEmitterAcceptanceTest.java index d708528c76..14589bb639 100644 --- a/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/EventEmitterAcceptanceTest.java +++ b/acceptance-tests/src/test/java/tech/pegasys/pantheon/tests/web3j/EventEmitterAcceptanceTest.java @@ -25,7 +25,6 @@ import java.math.BigInteger; import java.util.concurrent.atomic.AtomicBoolean; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.web3j.protocol.core.methods.request.EthFilter; import org.web3j.protocol.core.methods.response.TransactionReceipt; @@ -34,7 +33,6 @@ import rx.Observable; /* * This class is based around the EventEmitter solidity contract */ -@Ignore public class EventEmitterAcceptanceTest extends AcceptanceTestBase { private PantheonNode node;