Skip to content

Commit

Permalink
add tests for clearing the peerPromises map
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Jan 13, 2022
1 parent 9e39259 commit b57bcc8
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions gossip_tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestBrokenPromises(t *testing.T) {
gt.ThrottlePeer(peerC)

// make promises break
time.Sleep(GossipSubIWantFollowupTime + 10*time.Millisecond)
time.Sleep(gt.followUpTime + time.Millisecond)

brokenPromises = gt.GetBrokenPromises()
if len(brokenPromises) != 2 {
Expand All @@ -56,17 +56,17 @@ func TestBrokenPromises(t *testing.T) {
if brokenPromisesB != 1 {
t.Fatalf("expected 1 broken promise from A, got %d", brokenPromisesB)
}

// verify that the peerPromises map has been vacated
if len(gt.peerPromises) != 0 {
t.Fatal("expected empty peerPromises map")
}
}

func TestNoBrokenPromises(t *testing.T) {
// like above, but this time we deliver messages to fullfil the promises
originalGossipSubIWantFollowupTime := GossipSubIWantFollowupTime
GossipSubIWantFollowupTime = 100 * time.Millisecond
defer func() {
GossipSubIWantFollowupTime = originalGossipSubIWantFollowupTime
}()

gt := newGossipTracer()
gt.followUpTime = 100 * time.Millisecond

peerA := peer.ID("A")
peerB := peer.ID("B")
Expand All @@ -88,11 +88,16 @@ func TestNoBrokenPromises(t *testing.T) {
gt.DeliverMessage(&Message{Message: m})
}

time.Sleep(GossipSubIWantFollowupTime + 10*time.Millisecond)
time.Sleep(gt.followUpTime + time.Millisecond)

// there should be no broken promises
brokenPromises := gt.GetBrokenPromises()
if brokenPromises != nil {
t.Fatal("expected no broken promises")
}

// verify that the peerPromises map has been vacated
if len(gt.peerPromises) != 0 {
t.Fatal("expected empty peerPromises map")
}
}

0 comments on commit b57bcc8

Please sign in to comment.