fix test races

This commit is contained in:
vyzo 2020-09-03 12:34:20 +03:00
parent be1b155d45
commit 8408e700e2
1 changed files with 9 additions and 0 deletions

View File

@ -93,20 +93,29 @@ func TestPeerGater(t *testing.T) {
} }
pg.RemovePeer(peerA) pg.RemovePeer(peerA)
pg.Lock()
_, ok := pg.peerStats[peerA] _, ok := pg.peerStats[peerA]
pg.Unlock()
if ok { if ok {
t.Fatal("still have a stat record for peerA") t.Fatal("still have a stat record for peerA")
} }
pg.Lock()
_, ok = pg.ipStats[peerAip] _, ok = pg.ipStats[peerAip]
pg.Unlock()
if !ok { if !ok {
t.Fatal("expected to still have a stat record for peerA's ip") t.Fatal("expected to still have a stat record for peerA's ip")
} }
pg.Lock()
pg.ipStats[peerAip].expire = time.Now() pg.ipStats[peerAip].expire = time.Now()
pg.Unlock()
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
pg.Lock()
_, ok = pg.ipStats["1.2.3.4"] _, ok = pg.ipStats["1.2.3.4"]
pg.Unlock()
if ok { if ok {
t.Fatal("still have a stat record for peerA's ip") t.Fatal("still have a stat record for peerA's ip")
} }