Browse code

remove waitAndAssert and type casts

Signed-off-by: Tibor Vass <tibor@docker.com>

Tibor Vass authored on 2019/08/27 01:04:47
Showing 2 changed files
... ...
@@ -316,7 +316,7 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaderElection(c *testing.T) {
316 316
 		followers []*daemon.Daemon // keep track of followers
317 317
 	)
318 318
 	var lastErr error
319
-	checkLeader := func(nodes ...*daemon.Daemon) interface{} {
319
+	checkLeader := func(nodes ...*daemon.Daemon) checkF {
320 320
 		return func(c *testing.T) (interface{}, string) {
321 321
 			// clear these out before each run
322 322
 			leader = nil
... ...
@@ -413,41 +413,12 @@ func getErrorMessage(c *testing.T, body []byte) string {
413 413
 	return strings.TrimSpace(resp.Message)
414 414
 }
415 415
 
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
-
444 416
 type checkF func(*testing.T) (interface{}, string)
445 417
 type reducer func(...interface{}) interface{}
446 418
 
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 {
448 420
 	return func(poll.LogT) poll.Result {
449
-		ff := f.(checkF)
450
-		v, comment := ff(t)
421
+		v, comment := f(t)
451 422
 		if assert.Check(t, compare(v)) {
452 423
 			return poll.Success()
453 424
 		}
... ...
@@ -455,12 +426,12 @@ func pollCheck(t *testing.T, f interface{}, compare func(x interface{}) assert.B
455 455
 	}
456 456
 }
457 457
 
458
-func reducedCheck(r reducer, funcs ...interface{}) checkF {
458
+func reducedCheck(r reducer, funcs ...checkF) checkF {
459 459
 	return func(c *testing.T) (interface{}, string) {
460 460
 		var values []interface{}
461 461
 		var comments []string
462 462
 		for _, f := range funcs {
463
-			v, comment := f.(checkF)(c)
463
+			v, comment := f(c)
464 464
 			values = append(values, v)
465 465
 			if len(comment) > 0 {
466 466
 				comments = append(comments, comment)