From 79124086426162401b3553347d7c4b905be2dd06 Mon Sep 17 00:00:00 2001 From: vyzo Date: Thu, 3 Sep 2020 01:33:03 +0300 Subject: [PATCH] fix non-determinism in test --- peer_gater_test.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/peer_gater_test.go b/peer_gater_test.go index 488a216..5c857b0 100644 --- a/peer_gater_test.go +++ b/peer_gater_test.go @@ -38,15 +38,19 @@ func TestPeerGater(t *testing.T) { t.Fatal("expected AcceptAll") } - pg.RejectMessage(msg, rejectValidationIgnored) - status = pg.AcceptFrom(peerA) - if status != AcceptControl { - t.Fatal("expected AcceptControl") + for i := 0; i < 100; i++ { + pg.RejectMessage(msg, rejectValidationIgnored) + pg.RejectMessage(msg, rejectValidationFailed) } - pg.RejectMessage(msg, rejectValidationFailed) - status = pg.AcceptFrom(peerA) - if status != AcceptControl { + accepted := false + for i := 0; !accepted && i < 1000; i++ { + status = pg.AcceptFrom(peerA) + if status == AcceptControl { + accepted = true + } + } + if !accepted { t.Fatal("expected AcceptControl") } @@ -54,7 +58,7 @@ func TestPeerGater(t *testing.T) { pg.DeliverMessage(msg) } - accepted := false + accepted = false for i := 0; !accepted && i < 1000; i++ { status = pg.AcceptFrom(peerA) if status == AcceptAll {