Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Commit

Permalink
test: make bandwidth test less timing dependent
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed Jul 13, 2021
1 parent 28b4f85 commit 16ebbb1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions metrics/bandwidth_test.go
Expand Up @@ -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)
Expand Down

0 comments on commit 16ebbb1

Please sign in to comment.