From 16ebbb14949cd9d123a2b6a454f2a917f4d1583c Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 12 Jul 2021 17:00:07 -0700 Subject: [PATCH] test: make bandwidth test less timing dependent --- metrics/bandwidth_test.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/metrics/bandwidth_test.go b/metrics/bandwidth_test.go index 9f74057..2ceea42 100644 --- a/metrics/bandwidth_test.go +++ b/metrics/bandwidth_test.go @@ -146,16 +146,26 @@ func TestResetBandwidthCounter(t *testing.T) { bwc.LogSentMessageStream(100, proto, p) bwc.LogRecvMessageStream(50, proto, p) - time.Sleep(1*time.Second + time.Millisecond) + time.Sleep(time.Second) bwc.LogSentMessage(42) bwc.LogRecvMessage(24) bwc.LogSentMessageStream(100, proto, p) bwc.LogRecvMessageStream(50, proto, p) - time.Sleep(1*time.Second + time.Millisecond) + time.Sleep(time.Second) { + // wait for all messages to be received. + for i := 0; i < 10; i++ { + stats := bwc.GetBandwidthTotals() + if stats.TotalOut == 84 { + break + } + time.Sleep(time.Millisecond) + } + + // Then make sure everything is correct. stats := bwc.GetBandwidthTotals() assertEq(t, 84, stats.TotalOut) assertEq(t, 48, stats.TotalIn)