diff --git a/.golangci.yaml b/.golangci.yaml index 89f7e338..abaa08af 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -4,12 +4,6 @@ run: build-tags: - e2e - skip-dirs: - - pkg/client - - skip-files: - - "^prom.png$" - linters: enable: - asciicheck @@ -56,3 +50,9 @@ issues: - text: "ST1000: at least one file in a package should have a package comment" linters: - stylecheck + + exclude-dirs: + - pkg/client + + exclude-files: + - "^prom.png$" \ No newline at end of file diff --git a/pkg/reconciler/autoscaling/hpa/keda_hpa_test.go b/pkg/reconciler/autoscaling/hpa/keda_hpa_test.go index 1f0eaefd..b7356021 100644 --- a/pkg/reconciler/autoscaling/hpa/keda_hpa_test.go +++ b/pkg/reconciler/autoscaling/hpa/keda_hpa_test.go @@ -69,9 +69,9 @@ import ( _ "knative.dev/autoscaler-keda/pkg/client/injection/informers/keda/v1alpha1/scaledobject/fake" - . "knative.dev/pkg/reconciler/testing" - . "knative.dev/serving/pkg/reconciler/testing/v1" - . "knative.dev/serving/pkg/testing" + reconcilertesting "knative.dev/pkg/reconciler/testing" + testingv1 "knative.dev/serving/pkg/reconciler/testing/v1" + . "knative.dev/serving/pkg/testing" //nolint:all kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" ) @@ -82,7 +82,7 @@ const ( ) func TestControllerCanReconcile(t *testing.T) { - ctx, cancel, infs := SetupFakeContextWithCancel(t) + ctx, cancel, infs := reconcilertesting.SetupFakeContextWithCancel(t) ctl := NewController(ctx, configmap.NewStaticWatcher( &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{ @@ -108,7 +108,7 @@ func TestControllerCanReconcile(t *testing.T) { Data: map[string]string{}, })) - waitInformers, err := RunAndSyncInformers(ctx, infs...) + waitInformers, err := reconcilertesting.RunAndSyncInformers(ctx, infs...) if err != nil { t.Fatal("Failed to start informers:", err) } @@ -142,7 +142,7 @@ func TestReconcile(t *testing.T) { deployName := testRevision + "-deployment" privateSvc := names.PrivateService(testRevision) - table := TableTest{{ + table := reconcilertesting.TableTest{{ Name: "no op", Objects: []runtime.Object{ hpa(pa(testNamespace, testRevision, WithHPAClass, WithMetricAnnotation("cpu"))), @@ -273,14 +273,14 @@ func TestReconcile(t *testing.T) { }, Key: key(testNamespace, testRevision), WithReactors: []ktesting.ReactionFunc{ - InduceFailure("update", "serverlessservices"), + reconcilertesting.InduceFailure("update", "serverlessservices"), }, WantErr: true, WantUpdates: []ktesting.UpdateActionImpl{{ Object: sks(testNamespace, testRevision, WithDeployRef(deployName), WithSKSReady), }}, WantEvents: []string{ - Eventf(corev1.EventTypeWarning, "InternalError", "error reconciling SKS: error updating SKS test-revision: inducing failure for update serverlessservices"), + reconcilertesting.Eventf(corev1.EventTypeWarning, "InternalError", "error reconciling SKS: error updating SKS test-revision: inducing failure for update serverlessservices"), }, }, { Name: "create sks - create fails", @@ -291,14 +291,14 @@ func TestReconcile(t *testing.T) { }, Key: key(testNamespace, testRevision), WithReactors: []ktesting.ReactionFunc{ - InduceFailure("create", "serverlessservices"), + reconcilertesting.InduceFailure("create", "serverlessservices"), }, WantErr: true, WantCreates: []runtime.Object{ sks(testNamespace, testRevision, WithDeployRef(deployName)), }, WantEvents: []string{ - Eventf(corev1.EventTypeWarning, "InternalError", "error reconciling SKS: error creating SKS test-revision: inducing failure for create serverlessservices"), + reconcilertesting.Eventf(corev1.EventTypeWarning, "InternalError", "error reconciling SKS: error creating SKS test-revision: inducing failure for create serverlessservices"), }, }, { Name: "sks is disowned", @@ -314,7 +314,7 @@ func TestReconcile(t *testing.T) { Object: pa(testNamespace, testRevision, WithHPAClass, MarkResourceNotOwnedByPA("ServerlessService", testRevision)), }}, WantEvents: []string{ - Eventf(corev1.EventTypeWarning, "InternalError", `error reconciling SKS: PA: test-revision does not own SKS: test-revision`), + reconcilertesting.Eventf(corev1.EventTypeWarning, "InternalError", `error reconciling SKS: PA: test-revision does not own SKS: test-revision`), }, }, { Name: "pa is disowned", @@ -330,7 +330,7 @@ func TestReconcile(t *testing.T) { Object: pa(testNamespace, testRevision, WithHPAClass, MarkResourceNotOwnedByPA("ScaledObject", testRevision)), }}, WantEvents: []string{ - Eventf(corev1.EventTypeWarning, "InternalError", + reconcilertesting.Eventf(corev1.EventTypeWarning, "InternalError", `PodAutoscaler: "test-revision" does not own ScaledObject: "test-revision"`), }, }, { @@ -357,10 +357,10 @@ func TestReconcile(t *testing.T) { Key: key(testNamespace, testRevision), WantErr: true, WithReactors: []ktesting.ReactionFunc{ - InduceFailure("update", "podautoscalers"), + reconcilertesting.InduceFailure("update", "podautoscalers"), }, WantEvents: []string{ - Eventf(corev1.EventTypeWarning, "UpdateFailed", `Failed to update status for "test-revision": inducing failure for update podautoscalers`), + reconcilertesting.Eventf(corev1.EventTypeWarning, "UpdateFailed", `Failed to update status for "test-revision": inducing failure for update podautoscalers`), }, }, { Name: "invalid key", @@ -370,7 +370,7 @@ func TestReconcile(t *testing.T) { Key: "sandwich///", }} - table.Test(t, MakeFactory(func(ctx context.Context, listers *Listers, cmw configmap.Watcher) controller.Reconciler { + table.Test(t, testingv1.MakeFactory(func(ctx context.Context, listers *testingv1.Listers, _ configmap.Watcher) controller.Reconciler { retryAttempted = false ctx = podscalable.WithDuck(ctx) ctx, _ = fakekedaclient.With(ctx) @@ -432,10 +432,6 @@ func pa(namespace, name string, options ...PodAutoscalerOption) *autoscalingv1al type hpaOption func(*autoscalingv2.HorizontalPodAutoscaler) -func withHPAOwnersRemoved(hpa *autoscalingv2.HorizontalPodAutoscaler) { - hpa.OwnerReferences = nil -} - func withScales(d, a int32) PodAutoscalerOption { return func(pa *autoscalingv1alpha1.PodAutoscaler) { pa.Status.DesiredScale, pa.Status.ActualScale = ptr.Int32(d), ptr.Int32(a) diff --git a/test/e2e/autoscale.go b/test/e2e/autoscale.go index 1aff3672..e6c9c1e1 100644 --- a/test/e2e/autoscale.go +++ b/test/e2e/autoscale.go @@ -163,22 +163,6 @@ func newVegetaHTTPClient(ctx *TestContext, url *url.URL) *http.Client { return spoof.Client } -func generateTrafficAtFixedConcurrency(ctx *TestContext, concurrency int, stopChan chan struct{}) error { - pacer := vegeta.ConstantPacer{} // Sends requests as quickly as possible, capped by MaxWorkers below. - - attacker := vegeta.NewAttacker( - vegeta.Timeout(0), // No timeout is enforced at all. - vegeta.Workers(uint64(concurrency)), - vegeta.MaxWorkers(uint64(concurrency)), - vegeta.Client(newVegetaHTTPClient(ctx, ctx.resources.Route.Status.URL.URL())), - ) - - target := getVegetaTarget(ctx.resources.Route.Status.URL.URL().Hostname(), "sleep", autoscaleSleep, test.ServingFlags.HTTPS) - - ctx.t.Logf("Maintaining %d concurrent requests.", concurrency) - return generateTraffic(ctx, attacker, pacer, stopChan, target) -} - func generateTrafficAtFixedRPS(ctx *TestContext, rps int, stopChan chan struct{}) error { pacer := vegeta.ConstantPacer{Freq: rps, Per: time.Second} attacker := vegeta.NewAttacker( diff --git a/test/test_images/metrics-test/main.go b/test/test_images/metrics-test/main.go index 27696d16..c2f23062 100644 --- a/test/test_images/metrics-test/main.go +++ b/test/test_images/metrics-test/main.go @@ -34,7 +34,7 @@ var ( }) ) -func hello(w http.ResponseWriter, req *http.Request) { +func hello(w http.ResponseWriter, _ *http.Request) { defer opsProcessed.Inc() fmt.Fprint(w, "Hello!") @@ -77,14 +77,12 @@ func main() { cancelCtx() }() - select { - case <-ctx.Done(): - if err := mainServer.Shutdown(context.Background()); err != nil { - fmt.Printf("failed to shutdown main server: %s\n", err) - } + <-ctx.Done() + if err := mainServer.Shutdown(context.Background()); err != nil { + fmt.Printf("failed to shutdown main server: %s\n", err) + } - if err := promServer.Shutdown(context.Background()); err != nil { - fmt.Printf("failed to shutdown Prometheus server: %s\n", err) - } + if err := promServer.Shutdown(context.Background()); err != nil { + fmt.Printf("failed to shutdown Prometheus server: %s\n", err) } }