We probably shouldn't leave the bitmessage node running after the test is finished
This commit is contained in:
parent
4913a21b11
commit
ac70a4b632
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user