mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-26 16:35:18 -04:00
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:
parent
6c188e35fa
commit
ec216a8702
1 changed files with 9 additions and 5 deletions
|
@ -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
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue