From fedb87bd57ead74f77349d90281c0dfaf784e3dd Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 8 May 2020 20:12:34 +0300 Subject: [PATCH] deflake TestGossipsubAttackSpamIHAVE travis managed to take more than 3 seconds for one or two heartbeat sleeps; give it 10 seconds. --- gossipsub_spam_test.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gossipsub_spam_test.go b/gossipsub_spam_test.go index e92248e..d6fa60c 100644 --- a/gossipsub_spam_test.go +++ b/gossipsub_spam_test.go @@ -131,6 +131,12 @@ func TestGossipsubAttackSpamIWANT(t *testing.T) { // Test that Gossipsub only responds to IHAVE with IWANT once per heartbeat func TestGossipsubAttackSpamIHAVE(t *testing.T) { + originalGossipSubIWantFollowupTime := GossipSubIWantFollowupTime + GossipSubIWantFollowupTime = 10 * time.Second + defer func() { + GossipSubIWantFollowupTime = originalGossipSubIWantFollowupTime + }() + ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -219,9 +225,6 @@ func TestGossipsubAttackSpamIHAVE(t *testing.T) { t.Fatalf("Expected 0 score, but got %f", score) } - // Wait for a hearbeat - time.Sleep(GossipSubHeartbeatInterval) - // Send a bunch of IHAVEs for i := 0; i < 3*GossipSubMaxIHaveLength; i++ { ihavelst := []string{"someid" + strconv.Itoa(i+100)} @@ -242,6 +245,8 @@ func TestGossipsubAttackSpamIHAVE(t *testing.T) { t.Fatalf("Expecting max %d IWANTs per heartbeat but received %d", GossipSubMaxIHaveLength, iwc-firstBatchCount) } + time.Sleep(GossipSubIWantFollowupTime) + // The score should now be negative because of broken promises score = ps.rt.(*GossipSubRouter).score.Score(attacker.ID()) if score >= 0 {