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.ports.NetworkHandler;
|
||||||
import ch.dissem.bitmessage.security.bc.BouncySecurity;
|
import ch.dissem.bitmessage.security.bc.BouncySecurity;
|
||||||
import ch.dissem.bitmessage.utils.Property;
|
import ch.dissem.bitmessage.utils.Property;
|
||||||
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
@ -41,13 +42,14 @@ public class NetworkHandlerTest {
|
|||||||
private static TestInventory peerInventory;
|
private static TestInventory peerInventory;
|
||||||
private static TestInventory nodeInventory;
|
private static TestInventory nodeInventory;
|
||||||
|
|
||||||
|
private static BitmessageContext peer;
|
||||||
private static BitmessageContext node;
|
private static BitmessageContext node;
|
||||||
private static NetworkHandler networkHandler;
|
private static NetworkHandler networkHandler;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() {
|
public static void setUp() {
|
||||||
peerInventory = new TestInventory();
|
peerInventory = new TestInventory();
|
||||||
BitmessageContext peer = new BitmessageContext.Builder()
|
peer = new BitmessageContext.Builder()
|
||||||
.addressRepo(Mockito.mock(AddressRepository.class))
|
.addressRepo(Mockito.mock(AddressRepository.class))
|
||||||
.inventory(peerInventory)
|
.inventory(peerInventory)
|
||||||
.messageRepo(Mockito.mock(MessageRepository.class))
|
.messageRepo(Mockito.mock(MessageRepository.class))
|
||||||
@ -73,6 +75,21 @@ public class NetworkHandlerTest {
|
|||||||
.build();
|
.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)
|
@Test(timeout = 20_000)
|
||||||
public void ensureNodesAreConnecting() {
|
public void ensureNodesAreConnecting() {
|
||||||
try {
|
try {
|
||||||
@ -140,13 +157,6 @@ public class NetworkHandlerTest {
|
|||||||
assertInventorySize(1, peerInventory);
|
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 {
|
private void assertInventorySize(int expected, TestInventory inventory) throws InterruptedException {
|
||||||
long timeout = System.currentTimeMillis() + 1000;
|
long timeout = System.currentTimeMillis() + 1000;
|
||||||
while (expected != inventory.getInventory().size() && System.currentTimeMillis() < timeout) {
|
while (expected != inventory.getInventory().size() && System.currentTimeMillis() < timeout) {
|
||||||
|
Loading…
Reference in New Issue
Block a user