Commit a38d8a9c authored by Dirk McCormick's avatar Dirk McCormick

fix: race in tests

parent c7e7afca
......@@ -94,6 +94,14 @@ func (fpt *fakePeerTagger) Unprotect(p peer.ID, tag string) bool {
return false
}
func (fpt *fakePeerTagger) isProtected(p peer.ID, tag string) bool {
fpt.lk.Lock()
defer fpt.lk.Unlock()
_, ok := fpt.protectedPeers[p][tag]
return ok
}
type fakeProviderFinder struct {
findMorePeersRequested chan cid.Cid
}
......
......@@ -406,7 +406,7 @@ func TestProtectConnFirstPeerToSendWantedBlock(t *testing.T) {
time.Sleep(10 * time.Millisecond)
// Expect peer A to be protected as it was first to send the block
if _, ok := fpt.protectedPeers[peerA][sidStr]; !ok {
if !fpt.isProtected(peerA, sidStr) {
t.Fatal("Expected first peer to send block to have protected connection")
}
......@@ -417,7 +417,7 @@ func TestProtectConnFirstPeerToSendWantedBlock(t *testing.T) {
time.Sleep(10 * time.Millisecond)
// Expect peer B not to be protected as it was not first to send the block
if _, ok := fpt.protectedPeers[peerB][sidStr]; ok {
if fpt.isProtected(peerB, sidStr) {
t.Fatal("Expected peer not to be protected")
}
......@@ -428,7 +428,7 @@ func TestProtectConnFirstPeerToSendWantedBlock(t *testing.T) {
time.Sleep(10 * time.Millisecond)
// Expect peer C not to be protected as we didn't want the block it sent
if _, ok := fpt.protectedPeers[peerC][sidStr]; ok {
if fpt.isProtected(peerC, sidStr) {
t.Fatal("Expected peer not to be protected")
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment