From 9fda9642d328001651c49ef60f64a0bb714bc3de Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 7 Feb 2017 08:57:39 +0100 Subject: [PATCH] lib/events: Make test even less timing dependent --- lib/events/events_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/events/events_test.go b/lib/events/events_test.go index aaa6816b2..9fbe6200c 100644 --- a/lib/events/events_test.go +++ b/lib/events/events_test.go @@ -101,12 +101,19 @@ func TestBufferOverflow(t *testing.T) { s := l.Subscribe(AllEvents) 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() const nEvents = BufferSize * 2 for i := 0; i < nEvents; i++ { 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) } }