From d0a54a476c1c12ce449feab212c6c383f7aba051 Mon Sep 17 00:00:00 2001 From: Ivan Vilata-i-Balaguer Date: Thu, 12 May 2016 12:27:14 +0200 Subject: [PATCH] Get number of mailbox messages from environment, create properly sized latch --- .../p2p/network/NetworkStressTest.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/network/src/test/java/io/bitsquare/p2p/network/NetworkStressTest.java b/network/src/test/java/io/bitsquare/p2p/network/NetworkStressTest.java index cd98a0fc6f..3ab27d6ad4 100644 --- a/network/src/test/java/io/bitsquare/p2p/network/NetworkStressTest.java +++ b/network/src/test/java/io/bitsquare/p2p/network/NetworkStressTest.java @@ -52,6 +52,8 @@ public class NetworkStressTest { private static final String TEST_DIR_ENVVAR = "STRESS_TEST_DIR"; /** Environment variable to specify the number of direct messages sent per peer. */ private static final String DIRECT_COUNT_ENVVAR = "STRESS_TEST_NDIRECT"; + /** Environment variable to specify the number of mailbox messages sent per peer. */ + private static final String MAILBOX_COUNT_ENVVAR = "STRESS_TEST_NMAILBOX"; /** Numeric identifier of the regtest Bitcoin network. */ private static final int REGTEST_NETWORK_ID = 2; @@ -62,6 +64,8 @@ public class NetworkStressTest { private static final int NPEERS_MIN = 3; /** Default number of direct messages to be sent by each peer. */ private static final int DIRECT_COUNT_DEFAULT = 100; + /** Default number of mailbox messages to be sent by each peer. */ + private static final int MAILBOX_COUNT_DEFAULT = 100; /** Minimum delay between direct messages in milliseconds, 25% larger than throttle limit. */ private static long MIN_DIRECT_DELAY_MILLIS = Math.round(1.25 * (1.0 / Connection.MSG_THROTTLE_PER_SEC) * 1000); @@ -89,6 +93,8 @@ public class NetworkStressTest { /** Number of direct messages to be sent by each peer. */ private int directCount = DIRECT_COUNT_DEFAULT; + /** Number of mailbox messages to be sent by each peer. */ + private int mailboxCount = MAILBOX_COUNT_DEFAULT; // Inspired by by Marc Peters. public static void main(String[] args) { @@ -146,6 +152,14 @@ public class NetworkStressTest { String.format("Direct messages sent per peer must not be negative: %d", directCount) ); + final String nMailboxEnv = System.getenv(MAILBOX_COUNT_ENVVAR); + if (nMailboxEnv != null && !nMailboxEnv.equals("")) + mailboxCount = Integer.parseInt(nMailboxEnv); + if (mailboxCount < 0) + throw new IllegalArgumentException( + String.format("Mailbox messages sent per peer must not be negative: %d", mailboxCount) + ); + /** A property where threads can indicate setup failure of local services (Tor node, hidden service). */ final BooleanProperty localServicesFailed = new SimpleBooleanProperty(false); /** A barrier to wait for concurrent setup of local services (Tor node, hidden service). */ @@ -374,6 +388,10 @@ public class NetworkStressTest { // Cycle through peers sending to others, stopping the peer // and starting one of the stopped peers. + // + // No sent latch here since the order of events is different + // depending on whether the message goes direct or via mailbox. + final CountDownLatch receivedMailboxLatch = new CountDownLatch(mailboxCount * nPeers); for (int firstOnline = 0, firstOffline = firstPeerDown; firstOnline < nPeers; firstOnline++, firstOffline = ++firstOffline % nPeers) { @@ -394,7 +412,9 @@ public class NetworkStressTest { startLatch.await(10, TimeUnit.SECONDS); print("put peer %d online", firstOffline); } - // TODO: Wait for nodes to receive messages. + // TODO: Wait for nodes to receive messages, use meaningful timeout. + assertLatch("timed out while receiving mailbox messages", + receivedMailboxLatch, 120, TimeUnit.SECONDS); } private void print(String message, Object... args) {