diff --git a/configmap/store_test.go b/configmap/store_test.go index 2c2527d2d..a522c98c9 100644 --- a/configmap/store_test.go +++ b/configmap/store_test.go @@ -78,7 +78,6 @@ func TestStoreBadConstructors(t *testing.T) { } func TestStoreWatchConfigs(t *testing.T) { - defer ClearAll() store := NewUntypedStore( "name", TestLogger(t), @@ -99,7 +98,7 @@ func TestStoreWatchConfigs(t *testing.T) { got := watcher.watches if diff := cmp.Diff(want, got, sortStrings); diff != "" { - t.Errorf("Unexpected configmap watches (-want, +got): %v", diff) + t.Errorf("Unexpected configmap watches (-want, +got):\n%s", diff) } } diff --git a/controller/controller_test.go b/controller/controller_test.go index 13d660177..800ef7a0e 100644 --- a/controller/controller_test.go +++ b/controller/controller_test.go @@ -737,7 +737,6 @@ func TestEnqueue(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - t.Cleanup(ClearAll) var rl workqueue.RateLimiter = testRateLimiter{t, 100 * time.Millisecond} impl := NewImplFull(&NopReconciler{}, ControllerOptions{WorkQueueName: "Testing", Logger: TestLogger(t), RateLimiter: rl}) test.work(impl) @@ -753,7 +752,6 @@ func TestEnqueue(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - t.Cleanup(ClearAll) impl := NewImplWithStats(&NopReconciler{}, TestLogger(t), "Testing", &FakeStatsReporter{}) test.work(impl) @@ -780,8 +778,6 @@ func TestEnqueueAfter(t *testing.T) { queueCheckTimeout = shortDelay + 500*time.Millisecond ) - t.Cleanup(ClearAll) - impl := NewImplWithStats(&NopReconciler{}, TestLogger(t), "Testing", &FakeStatsReporter{}) t.Cleanup(func() { impl.WorkQueue().ShutDown() @@ -858,8 +854,6 @@ func TestEnqueueKeyAfter(t *testing.T) { shortDelay = 50 * time.Millisecond ) - t.Cleanup(ClearAll) - impl := NewImplWithStats(&NopReconciler{}, TestLogger(t), "Testing", &FakeStatsReporter{}) t.Cleanup(func() { impl.WorkQueue().ShutDown() @@ -927,7 +921,6 @@ func (cr *CountingReconciler) Reconcile(context.Context, string) error { } func TestStartAndShutdown(t *testing.T) { - t.Cleanup(ClearAll) r := &CountingReconciler{} impl := NewImplWithStats(r, TestLogger(t), "Testing", &FakeStatsReporter{}) @@ -987,7 +980,6 @@ func (cr *countingLeaderAwareReconciler) Reconcile(ctx context.Context, key stri } func TestStartAndShutdownWithLeaderAwareNoElection(t *testing.T) { - t.Cleanup(ClearAll) promoted := make(chan struct{}) r := &countingLeaderAwareReconciler{ LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ @@ -1033,7 +1025,6 @@ func TestStartAndShutdownWithLeaderAwareNoElection(t *testing.T) { } func TestStartAndShutdownWithLeaderAwareWithLostElection(t *testing.T) { - t.Cleanup(ClearAll) promoted := make(chan struct{}) r := &countingLeaderAwareReconciler{ LeaderAwareFuncs: reconciler.LeaderAwareFuncs{ @@ -1100,7 +1091,6 @@ func TestStartAndShutdownWithLeaderAwareWithLostElection(t *testing.T) { } func TestStartAndShutdownWithWork(t *testing.T) { - t.Cleanup(ClearAll) r := &CountingReconciler{} reporter := &FakeStatsReporter{} impl := NewImplWithStats(r, TestLogger(t), "Testing", reporter) @@ -1181,8 +1171,6 @@ func TestStartAndShutdownWithErroringWork(t *testing.T) { item := types.NamespacedName{Namespace: "", Name: "bar"} - t.Cleanup(ClearAll) - impl := NewImplWithStats(&ErrorReconciler{}, TestLogger(t), "Testing", &FakeStatsReporter{}) impl.EnqueueKey(item) @@ -1234,7 +1222,6 @@ func (er *PermanentErrorReconciler) Reconcile(context.Context, string) error { } func TestStartAndShutdownWithPermanentErroringWork(t *testing.T) { - t.Cleanup(ClearAll) r := &PermanentErrorReconciler{} reporter := &FakeStatsReporter{} impl := NewImplWithStats(r, TestLogger(t), "Testing", reporter) @@ -1327,7 +1314,6 @@ func (*dummyStore) List() []interface{} { } func TestImplGlobalResync(t *testing.T) { - t.Cleanup(ClearAll) r := &CountingReconciler{} impl := NewImplWithStats(r, TestLogger(t), "Testing", &FakeStatsReporter{}) diff --git a/metrics/config_test.go b/metrics/config_test.go index 75d8ebbfe..7f4db5fad 100644 --- a/metrics/config_test.go +++ b/metrics/config_test.go @@ -535,7 +535,6 @@ func successTestsInit() { func TestGetMetricsConfig(t *testing.T) { for _, test := range errorTests { t.Run(test.name, func(t *testing.T) { - defer ClearAll() _, err := createMetricsConfig(test.ops, TestLogger(t)) if err == nil || err.Error() != test.expectedErr { t.Errorf("Wanted err: %v, got: %v", test.expectedErr, err) @@ -546,7 +545,6 @@ func TestGetMetricsConfig(t *testing.T) { successTestsInit() for _, test := range successTests { t.Run(test.name, func(t *testing.T) { - defer ClearAll() mc, err := createMetricsConfig(test.ops, TestLogger(t)) if err != nil { t.Errorf("Wanted valid config %v, got error %v", test.expectedConfig, err) @@ -640,7 +638,6 @@ func TestGetMetricsConfig_fromEnv(t *testing.T) { os.Setenv(test.varName, test.varValue) defer os.Unsetenv(test.varName) - defer ClearAll() mc, err := createMetricsConfig(test.ops, TestLogger(t)) if err != nil { t.Errorf("Wanted valid config %v, got error %v", test.expectedConfig, err) @@ -656,7 +653,6 @@ func TestGetMetricsConfig_fromEnv(t *testing.T) { os.Setenv(test.varName, test.varValue) defer os.Unsetenv(test.varName) - defer ClearAll() mc, err := createMetricsConfig(test.ops, TestLogger(t)) if mc != nil { t.Errorf("Wanted no config, got %v", mc) @@ -673,7 +669,6 @@ func TestIsNewExporterRequiredFromNilConfig(t *testing.T) { successTestsInit() for _, test := range successTests { t.Run(test.name, func(t *testing.T) { - defer ClearAll() mc, err := createMetricsConfig(test.ops, TestLogger(t)) if err != nil { t.Errorf("Wanted valid config %v, got error %v", test.expectedConfig, err) @@ -801,7 +796,6 @@ func TestUpdateExporter(t *testing.T) { successTestsInit() for _, test := range successTests[1:] { t.Run(test.name, func(t *testing.T) { - defer ClearAll() UpdateExporter(test.ops, TestLogger(t)) mConfig := getCurMetricsConfig() if mConfig == oldConfig { @@ -816,7 +810,6 @@ func TestUpdateExporter(t *testing.T) { for _, test := range errorTests { t.Run(test.name, func(t *testing.T) { - defer ClearAll() UpdateExporter(test.ops, TestLogger(t)) mConfig := getCurMetricsConfig() if mConfig != oldConfig { @@ -832,7 +825,6 @@ func TestUpdateExporterFromConfigMapWithOpts(t *testing.T) { successTestsInit() for _, test := range successTests[1:] { t.Run(test.name, func(t *testing.T) { - defer ClearAll() opts := ExporterOptions{ Component: test.ops.Component, Domain: test.ops.Domain, @@ -856,7 +848,6 @@ func TestUpdateExporterFromConfigMapWithOpts(t *testing.T) { } t.Run("ConfigMapSetErr", func(t *testing.T) { - defer ClearAll() opts := ExporterOptions{ Component: testComponent, Domain: servingDomain, @@ -870,7 +861,6 @@ func TestUpdateExporterFromConfigMapWithOpts(t *testing.T) { }) t.Run("MissingComponentErr", func(t *testing.T) { - defer ClearAll() opts := ExporterOptions{ Component: "", Domain: servingDomain, @@ -887,7 +877,6 @@ func TestUpdateExporter_doesNotCreateExporter(t *testing.T) { setCurMetricsConfig(nil) for _, test := range errorTests { t.Run(test.name, func(t *testing.T) { - defer ClearAll() UpdateExporter(test.ops, TestLogger(t)) mConfig := getCurMetricsConfig() if mConfig != nil { @@ -1047,7 +1036,6 @@ func TestStackdriverRecord(t *testing.T) { for name, data := range testCases { t.Run(name, func(t *testing.T) { - defer ClearAll() opts := ExporterOptions{ ConfigMap: data.opts, Domain: "knative.dev/internal/serving", diff --git a/webhook/resourcesemantics/validation/validation_deprecated_test.go b/webhook/resourcesemantics/validation/validation_deprecated_test.go index 4be9036c5..200e101df 100644 --- a/webhook/resourcesemantics/validation/validation_deprecated_test.go +++ b/webhook/resourcesemantics/validation/validation_deprecated_test.go @@ -489,7 +489,6 @@ func TestStrictValidation(t *testing.T) { for n, tc := range testCases { t.Run(n, func(t *testing.T) { - defer ClearAll() ctx := TestContextWithLogger(t) if tc.strict { ctx = apis.DisallowDeprecated(ctx) diff --git a/websocket/connection_test.go b/websocket/connection_test.go index db5d6795d..ad3ea7c15 100644 --- a/websocket/connection_test.go +++ b/websocket/connection_test.go @@ -339,8 +339,7 @@ func TestDoubleShutdown(t *testing.T) { } func TestDurableConnectionWhenConnectionBreaksDown(t *testing.T) { - defer ktesting.ClearAll() - testPayload := "test" + const testPayload = "test" reconnectChan := make(chan struct{}) upgrader := websocket.Upgrader{} @@ -379,9 +378,8 @@ func TestDurableConnectionWhenConnectionBreaksDown(t *testing.T) { } func TestDurableConnectionSendsPingsRegularly(t *testing.T) { - defer ktesting.ClearAll() // Reset pongTimeout to something quite short. - pongTimeout = 100 * time.Millisecond + const pongTimeout = 100 * time.Millisecond upgrader := websocket.Upgrader{}