Check reception of preliminary data in peers in network stress test

Need to check that the seed node boots first to avoid spurious failures.
This commit is contained in:
Ivan Vilata-i-Balaguer 2016-04-26 11:37:51 +02:00
parent a2d130219c
commit 1f2d755c64

View file

@ -31,6 +31,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
public class NetworkStressTest { public class NetworkStressTest {
/** Numeric identifier of the regtest Bitcoin network. */ /** Numeric identifier of the regtest Bitcoin network. */
@ -45,6 +46,9 @@ public class NetworkStressTest {
/** A list of peer nodes represented as P2P services. */ /** A list of peer nodes represented as P2P services. */
private List<P2PService> peerNodes = new ArrayList<>(); private List<P2PService> peerNodes = new ArrayList<>();
/** A barrier to wait for concurrent reception of preliminary data in peers. */
private CountDownLatch prelimDataLatch = new CountDownLatch(NPEERS);
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
/** A property where threads can indicate setup failure of local services (Tor node, hidden service). */ /** A property where threads can indicate setup failure of local services (Tor node, hidden service). */
@ -113,7 +117,8 @@ public class NetworkStressTest {
return new P2PServiceListener() { return new P2PServiceListener() {
@Override @Override
public void onRequestingDataCompleted() { public void onRequestingDataCompleted() {
// do nothing // successful result
NetworkStressTest.this.prelimDataLatch.countDown();
} }
@Override @Override
@ -174,8 +179,9 @@ public class NetworkStressTest {
@Test @Test
public void test() throws InterruptedException { public void test() throws InterruptedException {
// do nothing // Wait for peers to get their preliminary data.
Thread.sleep(30_000); org.junit.Assert.assertTrue("timed out while waiting for preliminary data",
prelimDataLatch.await(30, TimeUnit.SECONDS));
} }
private Path createTempDirectory() throws IOException { private Path createTempDirectory() throws IOException {