fix(swarm): make test not flaky

In the unlikely event that we generated a random number twice, the 2nd address would not get added. Ensure we loop until we have 20 addresses.

Pull-Request: #4030.
This commit is contained in:
Thomas Eizinger 2023-06-05 22:37:06 +02:00 committed by GitHub
parent 1d3db7d9a8
commit 2f8e1489c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -126,7 +126,7 @@ mod tests {
fn when_pushing_more_than_max_addresses_oldest_is_evicted() {
let mut addresses = ExternalAddresses::default();
for _ in 0..MAX_LOCAL_EXTERNAL_ADDRS {
while addresses.as_slice().len() < MAX_LOCAL_EXTERNAL_ADDRS {
let random_address =
Multiaddr::empty().with(Protocol::Memory(rand::thread_rng().gen_range(0..1000)));
addresses.on_swarm_event(