remove waitAndAssert and type casts

Signed-off-by: Tibor Vass <tibor@docker.com>
This commit is contained in:
Tibor Vass 2019-08-26 16:04:47 +00:00
parent 40f1950e8e
commit 649201dc44
2 changed files with 5 additions and 34 deletions

View File

@ -316,7 +316,7 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaderElection(c *testing.T) {
followers []*daemon.Daemon // keep track of followers
)
var lastErr error
checkLeader := func(nodes ...*daemon.Daemon) interface{} {
checkLeader := func(nodes ...*daemon.Daemon) checkF {
return func(c *testing.T) (interface{}, string) {
// clear these out before each run
leader = nil

View File

@ -413,41 +413,12 @@ func getErrorMessage(c *testing.T, body []byte) string {
return strings.TrimSpace(resp.Message)
}
func waitAndAssert(t *testing.T, timeout time.Duration, f interface{}, comparison interface{}, args ...interface{}) {
t1 := time.Now()
defer func() {
t2 := time.Now()
t.Logf("waited for %v (out of %v)", t2.Sub(t1), timeout)
}()
after := time.After(timeout)
for {
v, comment := f.(checkF)(t)
args = append([]interface{}{v}, args...)
shouldAssert := assert.Check(t, comparison, args...)
select {
case <-after:
shouldAssert = true
default:
}
if shouldAssert {
if len(comment) > 0 {
args = append(args, comment)
}
assert.Assert(t, comparison, args...)
return
}
time.Sleep(100 * time.Millisecond)
}
}
type checkF func(*testing.T) (interface{}, string)
type reducer func(...interface{}) interface{}
func pollCheck(t *testing.T, f interface{}, compare func(x interface{}) assert.BoolOrComparison) poll.Check {
func pollCheck(t *testing.T, f checkF, compare func(x interface{}) assert.BoolOrComparison) poll.Check {
return func(poll.LogT) poll.Result {
ff := f.(checkF)
v, comment := ff(t)
v, comment := f(t)
if assert.Check(t, compare(v)) {
return poll.Success()
}
@ -455,12 +426,12 @@ func pollCheck(t *testing.T, f interface{}, compare func(x interface{}) assert.B
}
}
func reducedCheck(r reducer, funcs ...interface{}) checkF {
func reducedCheck(r reducer, funcs ...checkF) checkF {
return func(c *testing.T) (interface{}, string) {
var values []interface{}
var comments []string
for _, f := range funcs {
v, comment := f.(checkF)(c)
v, comment := f(c)
values = append(values, v)
if len(comment) > 0 {
comments = append(comments, comment)