mirror of
https://github.com/logos-messaging/go-libp2p-pubsub.git
synced 2026-01-05 22:33:10 +00:00
add tests for clearing the peerPromises map
This commit is contained in:
parent
9e39259ffe
commit
b57bcc8b36
@ -40,7 +40,7 @@ func TestBrokenPromises(t *testing.T) {
|
|||||||
gt.ThrottlePeer(peerC)
|
gt.ThrottlePeer(peerC)
|
||||||
|
|
||||||
// make promises break
|
// make promises break
|
||||||
time.Sleep(GossipSubIWantFollowupTime + 10*time.Millisecond)
|
time.Sleep(gt.followUpTime + time.Millisecond)
|
||||||
|
|
||||||
brokenPromises = gt.GetBrokenPromises()
|
brokenPromises = gt.GetBrokenPromises()
|
||||||
if len(brokenPromises) != 2 {
|
if len(brokenPromises) != 2 {
|
||||||
@ -56,17 +56,17 @@ func TestBrokenPromises(t *testing.T) {
|
|||||||
if brokenPromisesB != 1 {
|
if brokenPromisesB != 1 {
|
||||||
t.Fatalf("expected 1 broken promise from A, got %d", brokenPromisesB)
|
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) {
|
func TestNoBrokenPromises(t *testing.T) {
|
||||||
// like above, but this time we deliver messages to fullfil the promises
|
// 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 := newGossipTracer()
|
||||||
|
gt.followUpTime = 100 * time.Millisecond
|
||||||
|
|
||||||
peerA := peer.ID("A")
|
peerA := peer.ID("A")
|
||||||
peerB := peer.ID("B")
|
peerB := peer.ID("B")
|
||||||
@ -88,11 +88,16 @@ func TestNoBrokenPromises(t *testing.T) {
|
|||||||
gt.DeliverMessage(&Message{Message: m})
|
gt.DeliverMessage(&Message{Message: m})
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(GossipSubIWantFollowupTime + 10*time.Millisecond)
|
time.Sleep(gt.followUpTime + time.Millisecond)
|
||||||
|
|
||||||
// there should be no broken promises
|
// there should be no broken promises
|
||||||
brokenPromises := gt.GetBrokenPromises()
|
brokenPromises := gt.GetBrokenPromises()
|
||||||
if brokenPromises != nil {
|
if brokenPromises != nil {
|
||||||
t.Fatal("expected no broken promises")
|
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")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user