Fix direct message loop in network stress test

The logic was broken and all sends where packed in the same (min delay, max delay) period. Now a variable ensures that the random delay gets added to the previous time.
This commit is contained in:
Ivan Vilata-i-Balaguer 2016-05-03 14:01:43 +02:00
parent 6c188e35fa
commit ec216a8702

View file

@ -204,14 +204,18 @@ public class NetworkStressTest {
receivedDirectLatch.countDown(); receivedDirectLatch.countDown();
}); });
long nextSendMillis = System.currentTimeMillis();
for (int i = 0; i < DIRECT_COUNT; i++) { for (int i = 0; i < DIRECT_COUNT; i++) {
// Select a random peer and send a direct message to it after a random delay // Select a random peer and send a direct message to it...
// not shorter than throttle limits.
final int dstPeerIdx = (int) (Math.random() * nPeers); final int dstPeerIdx = (int) (Math.random() * nPeers);
final P2PService dstPeer = peerNodes.get(dstPeerIdx); final P2PService dstPeer = peerNodes.get(dstPeerIdx);
final NodeAddress dstPeerAddress = dstPeer.getAddress(); final NodeAddress dstPeerAddress = dstPeer.getAddress();
//print("sending direct message from peer %s to %s", srcPeer.getAddress(), dstPeer.getAddress()); // ...after a random delay not shorter than throttle limits.
UserThread.runAfterRandomDelay(() -> srcPeer.sendEncryptedDirectMessage( nextSendMillis += Math.round(Math.random() * (MAX_DIRECT_DELAY_MILLIS - MIN_DIRECT_DELAY_MILLIS));
final long sendAfterMillis = nextSendMillis - System.currentTimeMillis();
/*print("sending direct message from peer %s to %s in %sms",
srcPeer.getAddress(), dstPeer.getAddress(), sendAfterMillis);*/
UserThread.runAfter(() -> srcPeer.sendEncryptedDirectMessage(
dstPeerAddress, peerPKRings.get(dstPeerIdx), dstPeerAddress, peerPKRings.get(dstPeerIdx),
new StressTestDirectMessage("test/" + dstPeerAddress), new SendDirectMessageListener() { new StressTestDirectMessage("test/" + dstPeerAddress), new SendDirectMessageListener() {
@Override @Override
@ -224,7 +228,7 @@ public class NetworkStressTest {
sentDirectFailed.set(true); sentDirectFailed.set(true);
sentDirectLatch.countDown(); sentDirectLatch.countDown();
} }
}), MIN_DIRECT_DELAY_MILLIS, MAX_DIRECT_DELAY_MILLIS, TimeUnit.MILLISECONDS }), sendAfterMillis, TimeUnit.MILLISECONDS
); );
} }
} }