From 6d4c3dbd209f992753d4122595483fdc13c5c5ef Mon Sep 17 00:00:00 2001 From: Stefan Bueringer Date: Thu, 19 Sep 2024 18:10:43 +0200 Subject: [PATCH] Enable race detector for top-level unit tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stefan Büringer buringerst@vmware.com --- Makefile | 21 ++++-- .../types/upstreamv1beta1/conversion_test.go | 4 ++ .../types/upstreamv1beta2/conversion_test.go | 4 ++ .../types/upstreamv1beta3/conversion_test.go | 4 ++ .../conversion_no_fuzz_test.go | 68 +++++++++++++++++++ .../types/upstreamv1beta4/conversion_test.go | 44 ++---------- .../machinepool_controller_test.go | 15 ++-- exp/ipam/api/v1alpha1/conversion_test.go | 4 ++ .../kubeadm/v1alpha3/conversion_test.go | 4 ++ .../kubeadm/v1alpha4/conversion_test.go | 4 ++ .../kubeadm/v1alpha3/conversion_test.go | 4 ++ .../kubeadm/v1alpha4/conversion_test.go | 4 ++ .../exp/addons/v1alpha3/conversion_test.go | 4 ++ .../exp/addons/v1alpha4/conversion_test.go | 4 ++ .../apis/core/exp/v1alpha3/conversion_test.go | 4 ++ .../apis/core/exp/v1alpha4/conversion_test.go | 4 ++ .../apis/core/v1alpha3/conversion_test.go | 4 ++ .../apis/core/v1alpha4/conversion_test.go | 4 ++ internal/test/envtest/environment.go | 11 +++ .../docker/api/v1alpha3/conversion_test.go | 4 ++ .../docker/api/v1alpha4/conversion_test.go | 4 ++ .../exp/api/v1alpha3/conversion_test.go | 4 ++ .../exp/api/v1alpha4/conversion_test.go | 4 ++ 23 files changed, 182 insertions(+), 49 deletions(-) create mode 100644 bootstrap/kubeadm/types/upstreamv1beta4/conversion_no_fuzz_test.go diff --git a/Makefile b/Makefile index 5646943b64ef..77629e0e5602 100644 --- a/Makefile +++ b/Makefile @@ -906,19 +906,30 @@ KUBEBUILDER_ASSETS ?= $(shell $(SETUP_ENVTEST) use --use-env -p path $(KUBEBUILD setup-envtest: $(SETUP_ENVTEST) ## Set up envtest (download kubebuilder assets) @echo KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) -.PHONY: test -test: $(SETUP_ENVTEST) ## Run unit and integration tests +.PHONY: test-no-race +test-no-race: $(SETUP_ENVTEST) ## Run unit and integration tests KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test ./... $(TEST_ARGS) +.PHONY: test +test: $(SETUP_ENVTEST) ## Run unit and integration tests with race detector + # Note: Fuzz tests are not executed with race detector because they would just time out. + # To achieve that, all files with fuzz tests have the "!race" build tag, to still run fuzz tests + # we have an additional `go test` run that focuses on "TestFuzzyConversion". + KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test -race ./... $(TEST_ARGS) + KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test -run "^TestFuzzyConversion$$" ./... $(TEST_ARGS) + .PHONY: test-verbose -test-verbose: ## Run unit and integration tests with verbose flag +test-verbose: ## Run unit and integration tests with race detector and with verbose flag $(MAKE) test TEST_ARGS="$(TEST_ARGS) -v" .PHONY: test-junit -test-junit: $(SETUP_ENVTEST) $(GOTESTSUM) ## Run unit and integration tests and generate a junit report - set +o errexit; (KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test -json ./... $(TEST_ARGS); echo $$? > $(ARTIFACTS)/junit.exitcode) | tee $(ARTIFACTS)/junit.stdout +test-junit: $(SETUP_ENVTEST) $(GOTESTSUM) ## Run unit and integration tests with race detector and generate a junit report + set +o errexit; (KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test -race -json ./... $(TEST_ARGS); echo $$? > $(ARTIFACTS)/junit.exitcode) | tee $(ARTIFACTS)/junit.stdout $(GOTESTSUM) --junitfile $(ARTIFACTS)/junit.xml --raw-command cat $(ARTIFACTS)/junit.stdout exit $$(cat $(ARTIFACTS)/junit.exitcode) + set +o errexit; (KUBEBUILDER_ASSETS="$(KUBEBUILDER_ASSETS)" go test -run "^TestFuzzyConversion$$" -json ./... $(TEST_ARGS); echo $$? > $(ARTIFACTS)/junit-fuzz.exitcode) | tee $(ARTIFACTS)/junit-fuzz.stdout + $(GOTESTSUM) --junitfile $(ARTIFACTS)/junit-fuzz.xml --raw-command cat $(ARTIFACTS)/junit-fuzz.stdout + exit $$(cat $(ARTIFACTS)/junit-fuzz.exitcode) .PHONY: test-cover test-cover: ## Run unit and integration tests and generate a coverage report diff --git a/bootstrap/kubeadm/types/upstreamv1beta1/conversion_test.go b/bootstrap/kubeadm/types/upstreamv1beta1/conversion_test.go index 1e12a1986600..005e665450a5 100644 --- a/bootstrap/kubeadm/types/upstreamv1beta1/conversion_test.go +++ b/bootstrap/kubeadm/types/upstreamv1beta1/conversion_test.go @@ -1,3 +1,5 @@ +//go:build !race + /* Copyright 2021 The Kubernetes Authors. @@ -27,6 +29,8 @@ import ( utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) +// Test is disabled when the race detector is enabled (via "//go:build !race" above) because otherwise the fuzz tests would just time out. + func TestFuzzyConversion(t *testing.T) { t.Run("for ClusterConfiguration", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Hub: &bootstrapv1.ClusterConfiguration{}, diff --git a/bootstrap/kubeadm/types/upstreamv1beta2/conversion_test.go b/bootstrap/kubeadm/types/upstreamv1beta2/conversion_test.go index 0e0371e20087..73035120be7e 100644 --- a/bootstrap/kubeadm/types/upstreamv1beta2/conversion_test.go +++ b/bootstrap/kubeadm/types/upstreamv1beta2/conversion_test.go @@ -1,3 +1,5 @@ +//go:build !race + /* Copyright 2021 The Kubernetes Authors. @@ -27,6 +29,8 @@ import ( utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) +// Test is disabled when the race detector is enabled (via "//go:build !race" above) because otherwise the fuzz tests would just time out. + func TestFuzzyConversion(t *testing.T) { t.Run("for ClusterConfiguration", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Hub: &bootstrapv1.ClusterConfiguration{}, diff --git a/bootstrap/kubeadm/types/upstreamv1beta3/conversion_test.go b/bootstrap/kubeadm/types/upstreamv1beta3/conversion_test.go index 8a0c710eb377..32826f414eb4 100644 --- a/bootstrap/kubeadm/types/upstreamv1beta3/conversion_test.go +++ b/bootstrap/kubeadm/types/upstreamv1beta3/conversion_test.go @@ -1,3 +1,5 @@ +//go:build !race + /* Copyright 2021 The Kubernetes Authors. @@ -29,6 +31,8 @@ import ( utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) +// Test is disabled when the race detector is enabled (via "//go:build !race" above) because otherwise the fuzz tests would just time out. + func TestFuzzyConversion(t *testing.T) { g := NewWithT(t) scheme := runtime.NewScheme() diff --git a/bootstrap/kubeadm/types/upstreamv1beta4/conversion_no_fuzz_test.go b/bootstrap/kubeadm/types/upstreamv1beta4/conversion_no_fuzz_test.go new file mode 100644 index 000000000000..719fe8daeaec --- /dev/null +++ b/bootstrap/kubeadm/types/upstreamv1beta4/conversion_no_fuzz_test.go @@ -0,0 +1,68 @@ +/* +Copyright 2021 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package upstreamv1beta4 + +import ( + "testing" + "time" + + . "github.com/onsi/gomega" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1beta1" +) + +// This test case has been moved out of conversion_test.go because it should be run with the race detector. +// Note: The tests in conversion_test.go are disabled when the race detector is enabled (via "//go:build !race") because otherwise the fuzz tests would just time out. + +func TestTimeoutForControlPlaneMigration(t *testing.T) { + timeout := metav1.Duration{Duration: 10 * time.Second} + t.Run("from ClusterConfiguration to InitConfiguration and back", func(t *testing.T) { + g := NewWithT(t) + + clusterConfiguration := &bootstrapv1.ClusterConfiguration{ + APIServer: bootstrapv1.APIServer{TimeoutForControlPlane: &timeout}, + } + + initConfiguration := &InitConfiguration{} + err := initConfiguration.ConvertFromClusterConfiguration(clusterConfiguration) + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(initConfiguration.Timeouts.ControlPlaneComponentHealthCheck).To(Equal(&timeout)) + + clusterConfiguration = &bootstrapv1.ClusterConfiguration{} + err = initConfiguration.ConvertToClusterConfiguration(clusterConfiguration) + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(clusterConfiguration.APIServer.TimeoutForControlPlane).To(Equal(&timeout)) + }) + t.Run("from ClusterConfiguration to JoinConfiguration and back", func(t *testing.T) { + g := NewWithT(t) + + clusterConfiguration := &bootstrapv1.ClusterConfiguration{ + APIServer: bootstrapv1.APIServer{TimeoutForControlPlane: &timeout}, + } + + joinConfiguration := &JoinConfiguration{} + err := joinConfiguration.ConvertFromClusterConfiguration(clusterConfiguration) + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(joinConfiguration.Timeouts.ControlPlaneComponentHealthCheck).To(Equal(&timeout)) + + clusterConfiguration = &bootstrapv1.ClusterConfiguration{} + err = joinConfiguration.ConvertToClusterConfiguration(clusterConfiguration) + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(clusterConfiguration.APIServer.TimeoutForControlPlane).To(Equal(&timeout)) + }) +} diff --git a/bootstrap/kubeadm/types/upstreamv1beta4/conversion_test.go b/bootstrap/kubeadm/types/upstreamv1beta4/conversion_test.go index ada2c6415016..908d4af63bbb 100644 --- a/bootstrap/kubeadm/types/upstreamv1beta4/conversion_test.go +++ b/bootstrap/kubeadm/types/upstreamv1beta4/conversion_test.go @@ -1,3 +1,5 @@ +//go:build !race + /* Copyright 2021 The Kubernetes Authors. @@ -18,12 +20,10 @@ package upstreamv1beta4 import ( "testing" - "time" fuzz "github.com/google/gofuzz" . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer" @@ -31,6 +31,8 @@ import ( utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) +// Test is disabled when the race detector is enabled (via "//go:build !race" above) because otherwise the fuzz tests would just time out. + func TestFuzzyConversion(t *testing.T) { g := NewWithT(t) scheme := runtime.NewScheme() @@ -144,41 +146,3 @@ func bootstrapv1JoinConfigurationFuzzer(obj *bootstrapv1.JoinConfiguration, c fu obj.Discovery.File.KubeConfig = nil } } - -func TestTimeoutForControlPlaneMigration(t *testing.T) { - timeout := metav1.Duration{Duration: 10 * time.Second} - t.Run("from ClusterConfiguration to InitConfiguration and back", func(t *testing.T) { - g := NewWithT(t) - - clusterConfiguration := &bootstrapv1.ClusterConfiguration{ - APIServer: bootstrapv1.APIServer{TimeoutForControlPlane: &timeout}, - } - - initConfiguration := &InitConfiguration{} - err := initConfiguration.ConvertFromClusterConfiguration(clusterConfiguration) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(initConfiguration.Timeouts.ControlPlaneComponentHealthCheck).To(Equal(&timeout)) - - clusterConfiguration = &bootstrapv1.ClusterConfiguration{} - err = initConfiguration.ConvertToClusterConfiguration(clusterConfiguration) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(clusterConfiguration.APIServer.TimeoutForControlPlane).To(Equal(&timeout)) - }) - t.Run("from ClusterConfiguration to JoinConfiguration and back", func(t *testing.T) { - g := NewWithT(t) - - clusterConfiguration := &bootstrapv1.ClusterConfiguration{ - APIServer: bootstrapv1.APIServer{TimeoutForControlPlane: &timeout}, - } - - joinConfiguration := &JoinConfiguration{} - err := joinConfiguration.ConvertFromClusterConfiguration(clusterConfiguration) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(joinConfiguration.Timeouts.ControlPlaneComponentHealthCheck).To(Equal(&timeout)) - - clusterConfiguration = &bootstrapv1.ClusterConfiguration{} - err = joinConfiguration.ConvertToClusterConfiguration(clusterConfiguration) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(clusterConfiguration.APIServer.TimeoutForControlPlane).To(Equal(&timeout)) - }) -} diff --git a/exp/internal/controllers/machinepool_controller_test.go b/exp/internal/controllers/machinepool_controller_test.go index aa9de43469e9..31af2e75251f 100644 --- a/exp/internal/controllers/machinepool_controller_test.go +++ b/exp/internal/controllers/machinepool_controller_test.go @@ -24,10 +24,12 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" - "k8s.io/client-go/kubernetes/scheme" + "k8s.io/apimachinery/pkg/runtime" + clientgoscheme "k8s.io/client-go/kubernetes/scheme" "k8s.io/utils/ptr" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -834,6 +836,13 @@ func TestRemoveMachinePoolFinalizerAfterDeleteReconcile(t *testing.T) { } func TestMachinePoolConditions(t *testing.T) { + g := NewWithT(t) + scheme := runtime.NewScheme() + g.Expect(apiextensionsv1.AddToScheme(scheme)).To(Succeed()) + g.Expect(clientgoscheme.AddToScheme(scheme)).To(Succeed()) + g.Expect(clusterv1.AddToScheme(scheme)).To(Succeed()) + g.Expect(expv1.AddToScheme(scheme)).To(Succeed()) + testCluster := &clusterv1.Cluster{ ObjectMeta: metav1.ObjectMeta{Namespace: metav1.NamespaceDefault, Name: "test-cluster"}, } @@ -1079,9 +1088,7 @@ func TestMachinePoolConditions(t *testing.T) { tt.beforeFunc(bootstrap, infra, mp, nodes) } - g.Expect(clusterv1.AddToScheme(scheme.Scheme)).To(Succeed()) - - clientFake := fake.NewClientBuilder().WithObjects( + clientFake := fake.NewClientBuilder().WithScheme(scheme).WithObjects( testCluster, mp, infra, diff --git a/exp/ipam/api/v1alpha1/conversion_test.go b/exp/ipam/api/v1alpha1/conversion_test.go index 6d298ed2a3b8..f8e2f0b7b392 100644 --- a/exp/ipam/api/v1alpha1/conversion_test.go +++ b/exp/ipam/api/v1alpha1/conversion_test.go @@ -1,3 +1,5 @@ +//go:build !race + /* Copyright 2021 The Kubernetes Authors. @@ -25,6 +27,8 @@ import ( utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) +// Test is disabled when the race detector is enabled (via "//go:build !race" above) because otherwise the fuzz tests would just time out. + func TestFuzzyConversion(t *testing.T) { t.Run("for IPAddress", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Hub: &ipamv1.IPAddress{}, diff --git a/internal/apis/bootstrap/kubeadm/v1alpha3/conversion_test.go b/internal/apis/bootstrap/kubeadm/v1alpha3/conversion_test.go index cac6e82f4c9a..f55f1bbd2ada 100644 --- a/internal/apis/bootstrap/kubeadm/v1alpha3/conversion_test.go +++ b/internal/apis/bootstrap/kubeadm/v1alpha3/conversion_test.go @@ -1,3 +1,5 @@ +//go:build !race + /* Copyright 2020 The Kubernetes Authors. @@ -28,6 +30,8 @@ import ( utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) +// Test is disabled when the race detector is enabled (via "//go:build !race" above) because otherwise the fuzz tests would just time out. + func TestFuzzyConversion(t *testing.T) { t.Run("for KubeadmConfig", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Hub: &bootstrapv1.KubeadmConfig{}, diff --git a/internal/apis/bootstrap/kubeadm/v1alpha4/conversion_test.go b/internal/apis/bootstrap/kubeadm/v1alpha4/conversion_test.go index be6a5a20a9ab..bcf7af9adc15 100644 --- a/internal/apis/bootstrap/kubeadm/v1alpha4/conversion_test.go +++ b/internal/apis/bootstrap/kubeadm/v1alpha4/conversion_test.go @@ -1,3 +1,5 @@ +//go:build !race + /* Copyright 2021 The Kubernetes Authors. @@ -32,6 +34,8 @@ const ( fakeSecret = "abcdef0123456789" ) +// Test is disabled when the race detector is enabled (via "//go:build !race" above) because otherwise the fuzz tests would just time out. + func TestFuzzyConversion(t *testing.T) { t.Run("for KubeadmConfig", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Hub: &bootstrapv1.KubeadmConfig{}, diff --git a/internal/apis/controlplane/kubeadm/v1alpha3/conversion_test.go b/internal/apis/controlplane/kubeadm/v1alpha3/conversion_test.go index 2d8217c19da4..af5041520780 100644 --- a/internal/apis/controlplane/kubeadm/v1alpha3/conversion_test.go +++ b/internal/apis/controlplane/kubeadm/v1alpha3/conversion_test.go @@ -1,3 +1,5 @@ +//go:build !race + /* Copyright 2020 The Kubernetes Authors. @@ -29,6 +31,8 @@ import ( utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) +// Test is disabled when the race detector is enabled (via "//go:build !race" above) because otherwise the fuzz tests would just time out. + func TestFuzzyConversion(t *testing.T) { t.Run("for KubeadmControlPlane", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Hub: &controlplanev1.KubeadmControlPlane{}, diff --git a/internal/apis/controlplane/kubeadm/v1alpha4/conversion_test.go b/internal/apis/controlplane/kubeadm/v1alpha4/conversion_test.go index db232834f7b8..21f98d2e1966 100644 --- a/internal/apis/controlplane/kubeadm/v1alpha4/conversion_test.go +++ b/internal/apis/controlplane/kubeadm/v1alpha4/conversion_test.go @@ -1,3 +1,5 @@ +//go:build !race + /* Copyright 2020 The Kubernetes Authors. @@ -36,6 +38,8 @@ const ( fakeSecret = "abcdef0123456789" ) +// Test is disabled when the race detector is enabled (via "//go:build !race" above) because otherwise the fuzz tests would just time out. + func TestFuzzyConversion(t *testing.T) { t.Run("for KubeadmControlPlane", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Hub: &controlplanev1.KubeadmControlPlane{}, diff --git a/internal/apis/core/exp/addons/v1alpha3/conversion_test.go b/internal/apis/core/exp/addons/v1alpha3/conversion_test.go index 50cf6d755d5b..e3130f43df09 100644 --- a/internal/apis/core/exp/addons/v1alpha3/conversion_test.go +++ b/internal/apis/core/exp/addons/v1alpha3/conversion_test.go @@ -1,3 +1,5 @@ +//go:build !race + /* Copyright 2021 The Kubernetes Authors. @@ -23,6 +25,8 @@ import ( utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) +// Test is disabled when the race detector is enabled (via "//go:build !race" above) because otherwise the fuzz tests would just time out. + func TestFuzzyConversion(t *testing.T) { t.Run("for ClusterResourceSet", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Hub: &addonsv1.ClusterResourceSet{}, diff --git a/internal/apis/core/exp/addons/v1alpha4/conversion_test.go b/internal/apis/core/exp/addons/v1alpha4/conversion_test.go index 5c8eec356880..a6bfd42a0904 100644 --- a/internal/apis/core/exp/addons/v1alpha4/conversion_test.go +++ b/internal/apis/core/exp/addons/v1alpha4/conversion_test.go @@ -1,3 +1,5 @@ +//go:build !race + /* Copyright 2021 The Kubernetes Authors. @@ -23,6 +25,8 @@ import ( utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) +// Test is disabled when the race detector is enabled (via "//go:build !race" above) because otherwise the fuzz tests would just time out. + func TestFuzzyConversion(t *testing.T) { t.Run("for ClusterResourceSet", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Hub: &addonsv1.ClusterResourceSet{}, diff --git a/internal/apis/core/exp/v1alpha3/conversion_test.go b/internal/apis/core/exp/v1alpha3/conversion_test.go index 6df28a82fba7..ec17db16642c 100644 --- a/internal/apis/core/exp/v1alpha3/conversion_test.go +++ b/internal/apis/core/exp/v1alpha3/conversion_test.go @@ -1,3 +1,5 @@ +//go:build !race + /* Copyright 2021 The Kubernetes Authors. @@ -28,6 +30,8 @@ import ( utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) +// Test is disabled when the race detector is enabled (via "//go:build !race" above) because otherwise the fuzz tests would just time out. + func TestFuzzyConversion(t *testing.T) { t.Run("for MachinePool", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Hub: &expv1.MachinePool{}, diff --git a/internal/apis/core/exp/v1alpha4/conversion_test.go b/internal/apis/core/exp/v1alpha4/conversion_test.go index bfba3b1fb598..ff09b35416f1 100644 --- a/internal/apis/core/exp/v1alpha4/conversion_test.go +++ b/internal/apis/core/exp/v1alpha4/conversion_test.go @@ -1,3 +1,5 @@ +//go:build !race + /* Copyright 2021 The Kubernetes Authors. @@ -25,6 +27,8 @@ import ( utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) +// Test is disabled when the race detector is enabled (via "//go:build !race" above) because otherwise the fuzz tests would just time out. + func TestFuzzyConversion(t *testing.T) { t.Run("for MachinePool", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Hub: &expv1.MachinePool{}, diff --git a/internal/apis/core/v1alpha3/conversion_test.go b/internal/apis/core/v1alpha3/conversion_test.go index f685a42566dd..e60103709afe 100644 --- a/internal/apis/core/v1alpha3/conversion_test.go +++ b/internal/apis/core/v1alpha3/conversion_test.go @@ -1,3 +1,5 @@ +//go:build !race + /* Copyright 2020 The Kubernetes Authors. @@ -29,6 +31,8 @@ import ( utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) +// Test is disabled when the race detector is enabled (via "//go:build !race" above) because otherwise the fuzz tests would just time out. + func TestFuzzyConversion(t *testing.T) { t.Run("for Cluster", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Hub: &clusterv1.Cluster{}, diff --git a/internal/apis/core/v1alpha4/conversion_test.go b/internal/apis/core/v1alpha4/conversion_test.go index ce34632007d9..2b74481dc99e 100644 --- a/internal/apis/core/v1alpha4/conversion_test.go +++ b/internal/apis/core/v1alpha4/conversion_test.go @@ -1,3 +1,5 @@ +//go:build !race + /* Copyright 2021 The Kubernetes Authors. @@ -30,6 +32,8 @@ import ( utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) +// Test is disabled when the race detector is enabled (via "//go:build !race" above) because otherwise the fuzz tests would just time out. + func TestFuzzyConversion(t *testing.T) { t.Run("for Cluster", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Hub: &clusterv1.Cluster{}, diff --git a/internal/test/envtest/environment.go b/internal/test/envtest/environment.go index 0151e1ecad1a..fb915b143410 100644 --- a/internal/test/envtest/environment.go +++ b/internal/test/envtest/environment.go @@ -41,6 +41,8 @@ import ( "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" + "k8s.io/component-base/logs" + logsv1 "k8s.io/component-base/logs/api/v1" "k8s.io/klog/v2" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -71,6 +73,15 @@ import ( ) func init() { + // This has to be done so klog.Background() uses a proper logger. + // Otherwise it would fall back and log to os.Stderr. + // This would lead to race conditions because input.M.Run() writes os.Stderr + // while some go routines in controller-runtime use os.Stderr to write logs. + if err := logsv1.ValidateAndApply(logs.NewOptions(), nil); err != nil { + klog.ErrorS(err, "Unable to validate and apply log options") + os.Exit(1) + } + logger := klog.Background() // Use klog as the internal logger for this envtest environment. log.SetLogger(logger) diff --git a/test/infrastructure/docker/api/v1alpha3/conversion_test.go b/test/infrastructure/docker/api/v1alpha3/conversion_test.go index 234cdc14c917..c170061d77ba 100644 --- a/test/infrastructure/docker/api/v1alpha3/conversion_test.go +++ b/test/infrastructure/docker/api/v1alpha3/conversion_test.go @@ -1,3 +1,5 @@ +//go:build !race + /* Copyright 2021 The Kubernetes Authors. @@ -23,6 +25,8 @@ import ( utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) +// Test is disabled when the race detector is enabled (via "//go:build !race" above) because otherwise the fuzz tests would just time out. + func TestFuzzyConversion(t *testing.T) { t.Run("for DockerCluster", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Hub: &infrav1.DockerCluster{}, diff --git a/test/infrastructure/docker/api/v1alpha4/conversion_test.go b/test/infrastructure/docker/api/v1alpha4/conversion_test.go index e48abaeedd51..5a3dabd8c582 100644 --- a/test/infrastructure/docker/api/v1alpha4/conversion_test.go +++ b/test/infrastructure/docker/api/v1alpha4/conversion_test.go @@ -1,3 +1,5 @@ +//go:build !race + /* Copyright 2021 The Kubernetes Authors. @@ -23,6 +25,8 @@ import ( utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) +// Test is disabled when the race detector is enabled (via "//go:build !race" above) because otherwise the fuzz tests would just time out. + func TestFuzzyConversion(t *testing.T) { t.Run("for DockerCluster", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Hub: &infrav1.DockerCluster{}, diff --git a/test/infrastructure/docker/exp/api/v1alpha3/conversion_test.go b/test/infrastructure/docker/exp/api/v1alpha3/conversion_test.go index 9ece74966950..59e52d6c0c7e 100644 --- a/test/infrastructure/docker/exp/api/v1alpha3/conversion_test.go +++ b/test/infrastructure/docker/exp/api/v1alpha3/conversion_test.go @@ -1,3 +1,5 @@ +//go:build !race + /* Copyright 2021 The Kubernetes Authors. @@ -23,6 +25,8 @@ import ( utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) +// Test is disabled when the race detector is enabled (via "//go:build !race" above) because otherwise the fuzz tests would just time out. + func TestFuzzyConversion(t *testing.T) { t.Run("for DockerMachinePool", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Hub: &infraexpv1.DockerMachinePool{}, diff --git a/test/infrastructure/docker/exp/api/v1alpha4/conversion_test.go b/test/infrastructure/docker/exp/api/v1alpha4/conversion_test.go index 3df37e9fdbc6..ae6280c16e5b 100644 --- a/test/infrastructure/docker/exp/api/v1alpha4/conversion_test.go +++ b/test/infrastructure/docker/exp/api/v1alpha4/conversion_test.go @@ -1,3 +1,5 @@ +//go:build !race + /* Copyright 2021 The Kubernetes Authors. @@ -23,6 +25,8 @@ import ( utilconversion "sigs.k8s.io/cluster-api/util/conversion" ) +// Test is disabled when the race detector is enabled (via "//go:build !race" above) because otherwise the fuzz tests would just time out. + func TestFuzzyConversion(t *testing.T) { t.Run("for DockerMachinePool", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Hub: &infraexpv1.DockerMachinePool{},