Wait for mailbox send before stopping peer in network stress test

Otherwise the peer may be already stopped before sending.
This commit is contained in:
Ivan Vilata-i-Balaguer 2016-05-18 10:39:07 +02:00
parent ea35ace8db
commit 1a496e0963

View file

@ -402,6 +402,7 @@ public class NetworkStressTest {
// The first online peer sends messages to random other peers. // The first online peer sends messages to random other peers.
final P2PService onlinePeer = peerNodes.get(firstOnline); final P2PService onlinePeer = peerNodes.get(firstOnline);
final NodeAddress onlinePeerAddress = onlinePeer.getAddress(); final NodeAddress onlinePeerAddress = onlinePeer.getAddress();
final CountDownLatch sendLatch = new CountDownLatch(mailboxCount);
for (int i = 0; i < mailboxCount; i++) { for (int i = 0; i < mailboxCount; i++) {
// Select a random peer (different than source one)... // Select a random peer (different than source one)...
int peerIdx; int peerIdx;
@ -418,18 +419,24 @@ public class NetworkStressTest {
new SendMailboxMessageListener() { // checked in receiver new SendMailboxMessageListener() { // checked in receiver
@Override @Override
public void onArrived() { public void onArrived() {
sendLatch.countDown();
} }
@Override @Override
public void onStoredInMailbox() { public void onStoredInMailbox() {
sendLatch.countDown();
} }
@Override @Override
public void onFault(String errorMessage) { public void onFault(String errorMessage) {
sentMailboxFailed.set(true); sentMailboxFailed.set(true);
sendLatch.countDown();
} }
}); });
} }
// TODO: Use meaningful timeout.
assertLatch("timed out while sending from peer " + firstOnline,
sendLatch, 2 * mailboxCount, TimeUnit.SECONDS);
// When done, put first online peer offline. // When done, put first online peer offline.
final CountDownLatch stopLatch = new CountDownLatch(1); final CountDownLatch stopLatch = new CountDownLatch(1);