Skip to content

Commit

Permalink
Fix randomly failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Oct 28, 2014
1 parent fd24e6a commit 56d3963
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 56d3963

Please sign in to comment.