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)