From 56d396339b40f1fd2b62fce5b762a221d76d0042 Mon Sep 17 00:00:00 2001 From: Adrian Zankich Date: Tue, 28 Oct 2014 15:50:32 -0700 Subject: [PATCH] Fix randomly failing test --- utils_test.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/utils_test.go b/utils_test.go index f08902ba..1e291900 100644 --- a/utils_test.go +++ b/utils_test.go @@ -8,11 +8,18 @@ import ( func TestEvery(t *testing.T) { i := 0 + begin := time.Now().UnixNano() + sem := make(chan int64, 1) Every(2*time.Millisecond, func() { i++ + if i == 2 { + sem <- time.Now().UnixNano() + } }) - <-time.After(5 * time.Millisecond) - Assert(t, i, 2) + end := <-sem + if end-begin < 4000000 { + t.Error("Test should have taken at least 4 milliseconds") + } } func TestAfter(t *testing.T) {