lib/sync: Skip the timing tests if the host timer is flaky

This commit is contained in:
Jakob Borg 2016-03-27 10:41:38 +00:00 committed by Audrius Butkevicius
parent 17ed01a0c9
commit d91e6023eb

View File

@ -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