From 8408e700e2c2c43d2fcb8c79b9ae65cdc5fdec3c Mon Sep 17 00:00:00 2001 From: vyzo Date: Thu, 3 Sep 2020 12:34:20 +0300 Subject: [PATCH] fix test races --- peer_gater_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/peer_gater_test.go b/peer_gater_test.go index c3dea46..73a68fd 100644 --- a/peer_gater_test.go +++ b/peer_gater_test.go @@ -93,20 +93,29 @@ func TestPeerGater(t *testing.T) { } pg.RemovePeer(peerA) + pg.Lock() _, ok := pg.peerStats[peerA] + pg.Unlock() if ok { t.Fatal("still have a stat record for peerA") } + pg.Lock() _, ok = pg.ipStats[peerAip] + pg.Unlock() if !ok { t.Fatal("expected to still have a stat record for peerA's ip") } + pg.Lock() pg.ipStats[peerAip].expire = time.Now() + pg.Unlock() time.Sleep(2 * time.Second) + + pg.Lock() _, ok = pg.ipStats["1.2.3.4"] + pg.Unlock() if ok { t.Fatal("still have a stat record for peerA's ip") }