Fix randomly failing test
This commit is contained in:
parent
fd24e6a9fe
commit
56d396339b
|
@ -8,11 +8,18 @@ import (
|
||||||
|
|
||||||
func TestEvery(t *testing.T) {
|
func TestEvery(t *testing.T) {
|
||||||
i := 0
|
i := 0
|
||||||
|
begin := time.Now().UnixNano()
|
||||||
|
sem := make(chan int64, 1)
|
||||||
Every(2*time.Millisecond, func() {
|
Every(2*time.Millisecond, func() {
|
||||||
i++
|
i++
|
||||||
|
if i == 2 {
|
||||||
|
sem <- time.Now().UnixNano()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
<-time.After(5 * time.Millisecond)
|
end := <-sem
|
||||||
Assert(t, i, 2)
|
if end-begin < 4000000 {
|
||||||
|
t.Error("Test should have taken at least 4 milliseconds")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAfter(t *testing.T) {
|
func TestAfter(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue