Skip to content

Commit 649201d

Browse files
author
Tibor Vass
committed
remove waitAndAssert and type casts
Signed-off-by: Tibor Vass <tibor@docker.com>
1 parent 40f1950 commit 649201d

File tree

2 files changed

+5
-34
lines changed

2 files changed

+5
-34
lines changed

integration-cli/docker_api_swarm_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaderElection(c *testing.T) {
316316
followers []*daemon.Daemon // keep track of followers
317317
)
318318
var lastErr error
319-
checkLeader := func(nodes ...*daemon.Daemon) interface{} {
319+
checkLeader := func(nodes ...*daemon.Daemon) checkF {
320320
return func(c *testing.T) (interface{}, string) {
321321
// clear these out before each run
322322
leader = nil

integration-cli/docker_utils_test.go

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -413,54 +413,25 @@ func getErrorMessage(c *testing.T, body []byte) string {
413413
return strings.TrimSpace(resp.Message)
414414
}
415415

416-
func waitAndAssert(t *testing.T, timeout time.Duration, f interface{}, comparison interface{}, args ...interface{}) {
417-
t1 := time.Now()
418-
defer func() {
419-
t2 := time.Now()
420-
t.Logf("waited for %v (out of %v)", t2.Sub(t1), timeout)
421-
}()
422-
423-
after := time.After(timeout)
424-
for {
425-
v, comment := f.(checkF)(t)
426-
args = append([]interface{}{v}, args...)
427-
shouldAssert := assert.Check(t, comparison, args...)
428-
select {
429-
case <-after:
430-
shouldAssert = true
431-
default:
432-
}
433-
if shouldAssert {
434-
if len(comment) > 0 {
435-
args = append(args, comment)
436-
}
437-
assert.Assert(t, comparison, args...)
438-
return
439-
}
440-
time.Sleep(100 * time.Millisecond)
441-
}
442-
}
443-
444416
type checkF func(*testing.T) (interface{}, string)
445417
type reducer func(...interface{}) interface{}
446418

447-
func pollCheck(t *testing.T, f interface{}, compare func(x interface{}) assert.BoolOrComparison) poll.Check {
419+
func pollCheck(t *testing.T, f checkF, compare func(x interface{}) assert.BoolOrComparison) poll.Check {
448420
return func(poll.LogT) poll.Result {
449-
ff := f.(checkF)
450-
v, comment := ff(t)
421+
v, comment := f(t)
451422
if assert.Check(t, compare(v)) {
452423
return poll.Success()
453424
}
454425
return poll.Continue(comment)
455426
}
456427
}
457428

458-
func reducedCheck(r reducer, funcs ...interface{}) checkF {
429+
func reducedCheck(r reducer, funcs ...checkF) checkF {
459430
return func(c *testing.T) (interface{}, string) {
460431
var values []interface{}
461432
var comments []string
462433
for _, f := range funcs {
463-
v, comment := f.(checkF)(c)
434+
v, comment := f(c)
464435
values = append(values, v)
465436
if len(comment) > 0 {
466437
comments = append(comments, comment)

0 commit comments

Comments
 (0)