mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-03 18:20:27 +00:00
- Make poll take interfaces, do diff on error - Use poll in TestRegistryEvents - Improve the locking to prevent deadlocks and data races in registry_test.go
26 lines
459 B
Go
26 lines
459 B
Go
package test
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// Poll repeatedly evaluates condition until we either timeout, or it suceeds.
|
|
func Poll(t *testing.T, d time.Duration, want interface{}, have func() interface{}) {
|
|
deadline := time.Now().Add(d)
|
|
for {
|
|
if time.Now().After(deadline) {
|
|
break
|
|
}
|
|
if reflect.DeepEqual(want, have()) {
|
|
return
|
|
}
|
|
time.Sleep(d / 10)
|
|
}
|
|
h := have()
|
|
if reflect.DeepEqual(want, h) {
|
|
t.Fatal(Diff(want, h))
|
|
}
|
|
}
|