Commit da7f7eac authored by Dirk McCormick's avatar Dirk McCormick

test: fix flakey session peer manager tests

parent c980d7ed
...@@ -150,7 +150,8 @@ func TestOrderingPeers(t *testing.T) { ...@@ -150,7 +150,8 @@ func TestOrderingPeers(t *testing.T) {
ctx := context.Background() ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 30*time.Millisecond) ctx, cancel := context.WithTimeout(ctx, 30*time.Millisecond)
defer cancel() defer cancel()
peers := testutil.GeneratePeers(100) peerCount := 100
peers := testutil.GeneratePeers(peerCount)
completed := make(chan struct{}) completed := make(chan struct{})
fpt := &fakePeerTagger{} fpt := &fakePeerTagger{}
fppf := &fakePeerProviderFinder{peers, completed} fppf := &fakePeerProviderFinder{peers, completed}
...@@ -171,9 +172,10 @@ func TestOrderingPeers(t *testing.T) { ...@@ -171,9 +172,10 @@ func TestOrderingPeers(t *testing.T) {
sessionPeerManager.RecordPeerRequests(nil, c) sessionPeerManager.RecordPeerRequests(nil, c)
// record receives // record receives
peer1 := peers[rand.Intn(100)] randi := rand.Perm(peerCount)
peer2 := peers[rand.Intn(100)] peer1 := peers[randi[0]]
peer3 := peers[rand.Intn(100)] peer2 := peers[randi[1]]
peer3 := peers[randi[2]]
time.Sleep(1 * time.Millisecond) time.Sleep(1 * time.Millisecond)
sessionPeerManager.RecordPeerResponse(peer1, []cid.Cid{c[0]}) sessionPeerManager.RecordPeerResponse(peer1, []cid.Cid{c[0]})
time.Sleep(5 * time.Millisecond) time.Sleep(5 * time.Millisecond)
...@@ -358,7 +360,7 @@ func TestTimeoutsAndCancels(t *testing.T) { ...@@ -358,7 +360,7 @@ func TestTimeoutsAndCancels(t *testing.T) {
func TestUntaggingPeers(t *testing.T) { func TestUntaggingPeers(t *testing.T) {
ctx := context.Background() ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 10*time.Millisecond) ctx, cancel := context.WithTimeout(ctx, 30*time.Millisecond)
defer cancel() defer cancel()
peers := testutil.GeneratePeers(5) peers := testutil.GeneratePeers(5)
completed := make(chan struct{}) completed := make(chan struct{})
...@@ -375,7 +377,7 @@ func TestUntaggingPeers(t *testing.T) { ...@@ -375,7 +377,7 @@ func TestUntaggingPeers(t *testing.T) {
case <-ctx.Done(): case <-ctx.Done():
t.Fatal("Did not finish finding providers") t.Fatal("Did not finish finding providers")
} }
time.Sleep(2 * time.Millisecond) time.Sleep(15 * time.Millisecond)
if fpt.count() != len(peers) { if fpt.count() != len(peers) {
t.Fatal("Peers were not tagged!") t.Fatal("Peers were not tagged!")
......
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