From d91e6023eb434febb5ce4be7fff06974e6f9ee78 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Sun, 27 Mar 2016 10:41:38 +0000 Subject: [PATCH] lib/sync: Skip the timing tests if the host timer is flaky --- lib/sync/sync_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/lib/sync/sync_test.go b/lib/sync/sync_test.go index d8aedd39..511444d2 100644 --- a/lib/sync/sync_test.go +++ b/lib/sync/sync_test.go @@ -21,6 +21,23 @@ const ( longWait = 125 * time.Millisecond ) +var skipTimingTests = false + +func init() { + // Check a few times that a short sleep does not in fact overrun the log + // threshold. If it does, the timer accuracy is crap or the host is + // overloaded and we can't reliably run the tests in here. In the normal + // case this takes just 25*5 = 125 ms. + for i := 0; i < 25; i++ { + t0 := time.Now() + time.Sleep(shortWait) + if time.Since(t0) > logThreshold { + skipTimingTests = true + return + } + } +} + func TestTypes(t *testing.T) { debug = false l.SetDebug("sync", false) @@ -57,6 +74,11 @@ func TestTypes(t *testing.T) { } func TestMutex(t *testing.T) { + if skipTimingTests { + t.Skip("insufficient timer accuracy") + return + } + debug = true l.SetDebug("sync", true) threshold = logThreshold @@ -92,6 +114,11 @@ func TestMutex(t *testing.T) { } func TestRWMutex(t *testing.T) { + if skipTimingTests { + t.Skip("insufficient timer accuracy") + return + } + debug = true l.SetDebug("sync", true) threshold = logThreshold @@ -152,6 +179,11 @@ func TestRWMutex(t *testing.T) { } func TestWaitGroup(t *testing.T) { + if skipTimingTests { + t.Skip("insufficient timer accuracy") + return + } + debug = true l.SetDebug("sync", true) threshold = logThreshold