From 376ec111a3cd7513dec8bb4f148180e1030d12bb Mon Sep 17 00:00:00 2001 From: Antoine Toulme Date: Mon, 23 Dec 2019 09:33:16 -0800 Subject: [PATCH] Make sure to close Vert.x instances that are opened for testing (#280) Signed-off-by: Antoine Toulme --- .../java/org/hyperledger/besu/RunnerTest.java | 18 ++++++++++++++++-- .../hyperledger/besu/enclave/EnclaveTest.java | 6 ++++-- .../ethereum/retesteth/RetestethService.java | 1 + .../prometheus/MetricsHttpServiceTest.java | 1 + 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/besu/src/test/java/org/hyperledger/besu/RunnerTest.java b/besu/src/test/java/org/hyperledger/besu/RunnerTest.java index 2af4a86666..1385e18a46 100644 --- a/besu/src/test/java/org/hyperledger/besu/RunnerTest.java +++ b/besu/src/test/java/org/hyperledger/besu/RunnerTest.java @@ -82,6 +82,8 @@ import okhttp3.RequestBody; import okhttp3.Response; import org.apache.tuweni.units.bigints.UInt256; import org.awaitility.Awaitility; +import org.junit.After; +import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -94,6 +96,18 @@ public final class RunnerTest { private static final int MAX_BACKGROUND_COMPACTIONS = 4; private static final int BACKGROUND_THREAD_COUNT = 4; + private Vertx vertx; + + @Before + public void initVertx() { + vertx = Vertx.vertx(); + } + + @After + public void stopVertx() { + vertx.close(); + } + @Rule public final TemporaryFolder temp = new TemporaryFolder(); @Test @@ -179,7 +193,7 @@ public final class RunnerTest { final MetricsConfiguration aheadMetricsConfiguration = metricsConfiguration(); final RunnerBuilder runnerBuilder = new RunnerBuilder() - .vertx(Vertx.vertx()) + .vertx(vertx) .discovery(true) .p2pAdvertisedHost(listenHost) .p2pListenPort(0) @@ -313,7 +327,7 @@ public final class RunnerTest { }); final Future future = Future.future(); - final HttpClient httpClient = Vertx.vertx().createHttpClient(); + final HttpClient httpClient = vertx.createHttpClient(); httpClient.websocket( runnerBehind.getWebsocketPort().get(), WebSocketConfiguration.DEFAULT_WEBSOCKET_HOST, diff --git a/enclave/src/integration-test/java/org/hyperledger/besu/enclave/EnclaveTest.java b/enclave/src/integration-test/java/org/hyperledger/besu/enclave/EnclaveTest.java index 373cf089c6..540f212786 100644 --- a/enclave/src/integration-test/java/org/hyperledger/besu/enclave/EnclaveTest.java +++ b/enclave/src/integration-test/java/org/hyperledger/besu/enclave/EnclaveTest.java @@ -44,13 +44,15 @@ public class EnclaveTest { private static final String PAYLOAD = "a wonderful transaction"; private static final String MOCK_KEY = "iOCzoGo5kwtZU0J41Z9xnGXHN6ZNukIa9MspvHtu3Jk="; private static Enclave enclave; - private Vertx vertx = Vertx.vertx(); - private EnclaveFactory factory = new EnclaveFactory(vertx); + private Vertx vertx; + private EnclaveFactory factory; private static OrionTestHarness testHarness; @Before public void setUp() throws Exception { + vertx = Vertx.vertx(); + factory = new EnclaveFactory(vertx); folder.create(); testHarness = diff --git a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethService.java b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethService.java index 0ac4342b10..8fe02e4de2 100644 --- a/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethService.java +++ b/ethereum/retesteth/src/main/java/org/hyperledger/besu/ethereum/retesteth/RetestethService.java @@ -103,6 +103,7 @@ public class RetestethService { public void stop() { jsonRpcHttpService.stop(); + vertx.close(); } private static Map mapOf(final JsonRpcMethod... rpcMethods) { diff --git a/metrics/core/src/test/java/org/hyperledger/besu/metrics/prometheus/MetricsHttpServiceTest.java b/metrics/core/src/test/java/org/hyperledger/besu/metrics/prometheus/MetricsHttpServiceTest.java index abdd9a3747..477fa0f171 100644 --- a/metrics/core/src/test/java/org/hyperledger/besu/metrics/prometheus/MetricsHttpServiceTest.java +++ b/metrics/core/src/test/java/org/hyperledger/besu/metrics/prometheus/MetricsHttpServiceTest.java @@ -73,6 +73,7 @@ public class MetricsHttpServiceTest { @AfterClass public static void shutdownServer() { service.stop().join(); + vertx.close(); } @Test