From ac70a4b6323fc4ae77cc423dc7cf226d0a0f4ec0 Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Thu, 15 Oct 2015 17:59:32 +0200 Subject: [PATCH] We probably shouldn't leave the bitmessage node running after the test is finished --- .../networking/NetworkHandlerTest.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/networking/src/test/java/ch/dissem/bitmessage/networking/NetworkHandlerTest.java b/networking/src/test/java/ch/dissem/bitmessage/networking/NetworkHandlerTest.java index ee437e1..53ce36d 100644 --- a/networking/src/test/java/ch/dissem/bitmessage/networking/NetworkHandlerTest.java +++ b/networking/src/test/java/ch/dissem/bitmessage/networking/NetworkHandlerTest.java @@ -23,6 +23,7 @@ import ch.dissem.bitmessage.ports.MessageRepository; import ch.dissem.bitmessage.ports.NetworkHandler; import ch.dissem.bitmessage.security.bc.BouncySecurity; import ch.dissem.bitmessage.utils.Property; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.mockito.Mockito; @@ -41,13 +42,14 @@ public class NetworkHandlerTest { private static TestInventory peerInventory; private static TestInventory nodeInventory; + private static BitmessageContext peer; private static BitmessageContext node; private static NetworkHandler networkHandler; @BeforeClass public static void setUp() { peerInventory = new TestInventory(); - BitmessageContext peer = new BitmessageContext.Builder() + peer = new BitmessageContext.Builder() .addressRepo(Mockito.mock(AddressRepository.class)) .inventory(peerInventory) .messageRepo(Mockito.mock(MessageRepository.class)) @@ -73,6 +75,21 @@ public class NetworkHandlerTest { .build(); } + @AfterClass + public static void cleanUp() { + shutdown(peer); + } + + private static void shutdown(BitmessageContext node) { + node.shutdown(); + do { + try { + Thread.sleep(100); + } catch (InterruptedException ignore) { + } + } while (node.isRunning()); + } + @Test(timeout = 20_000) public void ensureNodesAreConnecting() { try { @@ -140,13 +157,6 @@ public class NetworkHandlerTest { assertInventorySize(1, peerInventory); } - private void shutdown(BitmessageContext node) { - node.shutdown(); - do { - Thread.yield(); - } while (node.isRunning()); - } - private void assertInventorySize(int expected, TestInventory inventory) throws InterruptedException { long timeout = System.currentTimeMillis() + 1000; while (expected != inventory.getInventory().size() && System.currentTimeMillis() < timeout) {