lib/events: Make test even less timing dependent

This commit is contained in:
Jakob Borg 2017-02-07 08:57:39 +01:00
parent dfd2c464b6
commit 9fda9642d3

View File

@ -101,12 +101,19 @@ func TestBufferOverflow(t *testing.T) {
s := l.Subscribe(AllEvents) s := l.Subscribe(AllEvents)
defer l.Unsubscribe(s) defer l.Unsubscribe(s)
// The first BufferSize events will be logged pretty much
// instantaneously. The next BufferSize events will each block for up to
// 15ms, plus overhead from race detector and thread scheduling latency
// etc. This latency can sometimes be significant and is incurred for
// each call. We just verify that the whole test completes in a
// reasonable time, taking no more than 15 seconds in total.
t0 := time.Now() t0 := time.Now()
const nEvents = BufferSize * 2 const nEvents = BufferSize * 2
for i := 0; i < nEvents; i++ { for i := 0; i < nEvents; i++ {
l.Log(DeviceConnected, "foo") l.Log(DeviceConnected, "foo")
} }
if d := time.Since(t0); d > nEvents*eventLogTimeout { if d := time.Since(t0); d > 15*time.Second {
t.Fatal("Logging took too long,", d, "avg", d/nEvents, "expected <", eventLogTimeout) t.Fatal("Logging took too long,", d, "avg", d/nEvents, "expected <", eventLogTimeout)
} }
} }