From 220d5c2e5439fb210c74264353534c7e9167c543 Mon Sep 17 00:00:00 2001 From: AxeZhan Date: Wed, 13 Sep 2023 13:34:49 +0800 Subject: [PATCH] remove dead code in test --- .../apimachinery/pkg/util/wait/loop_test.go | 60 ++++++++----------- 1 file changed, 26 insertions(+), 34 deletions(-) diff --git a/staging/src/k8s.io/apimachinery/pkg/util/wait/loop_test.go b/staging/src/k8s.io/apimachinery/pkg/util/wait/loop_test.go index 992d3d04da4..4250722f424 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/wait/loop_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/wait/loop_test.go @@ -206,42 +206,34 @@ func Test_loopConditionUntilContext_semantic(t *testing.T) { } for _, test := range tests { - for _, immediate := range []bool{true, false} { - t.Run(fmt.Sprintf("immediate=%t", immediate), func(t *testing.T) { - for _, sliding := range []bool{true, false} { - t.Run(fmt.Sprintf("sliding=%t", sliding), func(t *testing.T) { - t.Run(test.name, func(t *testing.T) { - contextFn := test.context - if contextFn == nil { - contextFn = defaultContext - } - ctx, cancel := contextFn() - defer cancel() + t.Run(test.name, func(t *testing.T) { + contextFn := test.context + if contextFn == nil { + contextFn = defaultContext + } + ctx, cancel := contextFn() + defer cancel() - timer := Backoff{Duration: time.Microsecond}.Timer() - attempts := 0 - err := loopConditionUntilContext(ctx, timer, test.immediate, test.sliding, func(_ context.Context) (bool, error) { - attempts++ - defer func() { - if test.cancelContextAfter > 0 && test.cancelContextAfter == attempts { - cancel() - } - }() - return test.callback(attempts) - }) - - if test.errExpected != err { - t.Errorf("expected error: %v but got: %v", test.errExpected, err) - } - - if test.attemptsExpected != attempts { - t.Errorf("expected attempts count: %d but got: %d", test.attemptsExpected, attempts) - } - }) - }) - } + timer := Backoff{Duration: time.Microsecond}.Timer() + attempts := 0 + err := loopConditionUntilContext(ctx, timer, test.immediate, test.sliding, func(_ context.Context) (bool, error) { + attempts++ + defer func() { + if test.cancelContextAfter > 0 && test.cancelContextAfter == attempts { + cancel() + } + }() + return test.callback(attempts) }) - } + + if test.errExpected != err { + t.Errorf("expected error: %v but got: %v", test.errExpected, err) + } + + if test.attemptsExpected != attempts { + t.Errorf("expected attempts count: %d but got: %d", test.attemptsExpected, attempts) + } + }) } }