From ac70e7e7386dc524dab53f19ae0b35efc0b1fc94 Mon Sep 17 00:00:00 2001 From: Yusef Napora Date: Thu, 23 Apr 2020 14:19:48 -0400 Subject: [PATCH] be less dependent on accurate time calculations in test thanks travis... --- score_test.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/score_test.go b/score_test.go index 4562d5c..0b68114 100644 --- a/score_test.go +++ b/score_test.go @@ -42,9 +42,8 @@ func TestScoreTimeInMesh(t *testing.T) { ps.refreshScores() aScore = ps.Score(peerA) expected := topicScoreParams.TopicWeight * topicScoreParams.TimeInMeshWeight * float64(elapsed/topicScoreParams.TimeInMeshQuantum) - variance := 0.5 - if !withinVariance(aScore, expected, variance) { - t.Fatalf("Score: %f. Expected %f ± %f", aScore, expected, variance*expected) + if aScore < expected { + t.Fatalf("Score: %f. Expected >= %f", aScore, expected) } } @@ -251,8 +250,7 @@ func TestScoreMeshMessageDeliveries(t *testing.T) { ps.Graft(p, mytopic) } - // wait for half the activation time, and assert that nobody has been penalized yet for not delivering messages - time.Sleep(topicScoreParams.MeshMessageDeliveriesActivation / time.Duration(2)) + // assert that nobody has been penalized yet for not delivering messages before activation time ps.refreshScores() for _, p := range peers { score := ps.Score(p) @@ -260,8 +258,8 @@ func TestScoreMeshMessageDeliveries(t *testing.T) { t.Fatalf("expected no mesh delivery penalty before activation time, got score %f", score) } } - // wait the remainder of the activation time - time.Sleep(topicScoreParams.MeshMessageDeliveriesActivation / time.Duration(2)) + // wait for the activation time to kick in + time.Sleep(topicScoreParams.MeshMessageDeliveriesActivation) // deliver a bunch of messages from peer A, with duplicates within the window from peer B, // and duplicates outside the window from peer C.