diff --git a/build/test.mk b/build/test.mk index 8c00b01be4..2aa1a20eb0 100644 --- a/build/test.mk +++ b/build/test.mk @@ -35,6 +35,7 @@ REL_VERSION ?=latest DOCKER_REGISTRY ?=ghcr.io/radius-project/dev ENVTEST_ASSETS_DIR=$(shell pwd)/bin K8S_VERSION=1.30.* +ENVTEST_ARCH ?= $(shell go env GOHOSTARCH) ENV_SETUP=$(GOBIN)/setup-envtest$(BINARY_EXT) # Use gotestsum if available, otherwise use go test. We want to enable testing with just 'make test' @@ -55,8 +56,8 @@ GOTEST_TOOL ?= gotestsum $(GOTESTSUM_OPTS) -- endif .PHONY: test -test: test-get-envtools test-helm ## Runs unit tests, excluding kubernetes controller tests - KUBEBUILDER_ASSETS="$(shell $(ENV_SETUP) use -p path ${K8S_VERSION} --arch amd64)" CGO_ENABLED=1 $(GOTEST_TOOL) -v ./pkg/... $(GOTEST_OPTS) +test: test-get-envtools test-helm ## Runs Go tests + KUBEBUILDER_ASSETS="$(shell $(ENV_SETUP) use -p path ${K8S_VERSION} --arch $(ENVTEST_ARCH))" CGO_ENABLED=1 $(GOTEST_TOOL) -v ./pkg/... $(GOTEST_OPTS) .PHONY: test-compile test-compile: test-get-envtools ## Compiles all tests without running them @@ -69,7 +70,7 @@ test-get-envtools: $(call go-install-tool,$(ENV_SETUP),sigs.k8s.io/controller-runtime/tools/setup-envtest@release-0.20) @echo "$(ARROW) Instructions:" @echo "$(ARROW) Set environment variable KUBEBUILDER_ASSETS for tests." - @echo "$(ARROW) KUBEBUILDER_ASSETS=\"$(shell $(ENV_SETUP) use -p path ${K8S_VERSION} --arch amd64)\"" + @echo "$(ARROW) KUBEBUILDER_ASSETS=\"$(shell $(ENV_SETUP) use -p path ${K8S_VERSION} --arch $(ENVTEST_ARCH))\"" .PHONY: test-validate-cli test-validate-cli: ## Run cli integration tests diff --git a/pkg/controller/reconciler/deployment_reconciler_test.go b/pkg/controller/reconciler/deployment_reconciler_test.go index 49f02207e5..d7a41cf960 100644 --- a/pkg/controller/reconciler/deployment_reconciler_test.go +++ b/pkg/controller/reconciler/deployment_reconciler_test.go @@ -42,7 +42,7 @@ import ( const ( deploymentTestWaitDuration = time.Second * 10 - deploymentTestWaitInterval = time.Second * 1 + deploymentTestWaitInterval = 200 * time.Millisecond deploymentTestControllerDelayInterval = time.Millisecond * 100 ) @@ -546,10 +546,8 @@ func Test_DeploymentReconciler_RadiusDisabled_ThenRadiusDisabled(t *testing.T) { func waitForStateWaiting(t *testing.T, client client.Client, name types.NamespacedName) *deploymentAnnotations { ctx := testcontext.New(t) - logger := t var annotations deploymentAnnotations require.EventuallyWithTf(t, func(t *assert.CollectT) { - logger.Logf("Fetching Deployment: %+v", name) current := &appsv1.Deployment{} err := client.Get(ctx, name, current) require.NoError(t, err) @@ -557,7 +555,6 @@ func waitForStateWaiting(t *testing.T, client client.Client, name types.Namespac annotations, err = readAnnotations(current) require.NoError(t, err) assert.NotNil(t, annotations) - logger.Logf("Annotations.Status: %+v", annotations.Status) if assert.NotNil(t, annotations.Status) && assert.Equal(t, deploymentPhraseWaiting, annotations.Status.Phrase) { assert.Empty(t, annotations.Status.Operation) @@ -570,10 +567,8 @@ func waitForStateWaiting(t *testing.T, client client.Client, name types.Namespac func waitForStateUpdating(t *testing.T, client client.Client, name types.NamespacedName) *deploymentAnnotations { ctx := testcontext.New(t) - logger := t var annotations deploymentAnnotations require.EventuallyWithTf(t, func(t *assert.CollectT) { - logger.Logf("Fetching Deployment: %+v", name) current := &appsv1.Deployment{} err := client.Get(ctx, name, current) require.NoError(t, err) @@ -581,7 +576,6 @@ func waitForStateUpdating(t *testing.T, client client.Client, name types.Namespa annotations, err = readAnnotations(current) require.NoError(t, err) assert.NotNil(t, annotations) - logger.Logf("Annotations.Status: %+v", annotations.Status) if assert.NotNil(t, annotations.Status) && assert.Equal(t, deploymentPhraseUpdating, annotations.Status.Phrase) { assert.NotEmpty(t, annotations.Status.Operation) @@ -594,10 +588,8 @@ func waitForStateUpdating(t *testing.T, client client.Client, name types.Namespa func waitForStateReady(t *testing.T, client client.Client, name types.NamespacedName) *deploymentAnnotations { ctx := testcontext.New(t) - logger := t var annotations deploymentAnnotations require.EventuallyWithTf(t, func(t *assert.CollectT) { - logger.Logf("Fetching Deployment: %+v", name) current := &appsv1.Deployment{} err := client.Get(ctx, name, current) require.NoError(t, err) @@ -605,7 +597,6 @@ func waitForStateReady(t *testing.T, client client.Client, name types.Namespaced annotations, err = readAnnotations(current) require.NoError(t, err) assert.NotNil(t, annotations) - logger.Logf("Annotations.Status: %+v", annotations.Status) if assert.NotNil(t, annotations.Status) && assert.Equal(t, deploymentPhraseReady, annotations.Status.Phrase) { assert.Empty(t, annotations.Status.Operation) @@ -618,10 +609,8 @@ func waitForStateReady(t *testing.T, client client.Client, name types.Namespaced func waitForStateDeleting(t *testing.T, client client.Client, name types.NamespacedName) *deploymentAnnotations { ctx := testcontext.New(t) - logger := t var annotations deploymentAnnotations require.EventuallyWithTf(t, func(t *assert.CollectT) { - logger.Logf("Fetching Deployment: %+v", name) current := &appsv1.Deployment{} err := client.Get(ctx, name, current) require.NoError(t, err) @@ -629,7 +618,6 @@ func waitForStateDeleting(t *testing.T, client client.Client, name types.Namespa annotations, err = readAnnotations(current) require.NoError(t, err) assert.NotNil(t, annotations) - logger.Logf("Annotations.Status: %+v", annotations.Status) if assert.NotNil(t, annotations.Status) && assert.Equal(t, deploymentPhraseDeleting, annotations.Status.Phrase) { assert.NotEmpty(t, annotations.Status.Operation) @@ -651,11 +639,8 @@ type expectedEvent struct { // We can have multiple events as the result of the List function but we are only interested in the expected event. func waitForEvent(t *testing.T, client client.Client, event expectedEvent) { ctx := testcontext.New(t) - logger := t require.EventuallyWithTf(t, func(t *assert.CollectT) { - logger.Log("Fetching Events") - events := &corev1.EventList{} err := client.List(ctx, events) require.NoError(t, err) @@ -675,15 +660,12 @@ func waitForEvent(t *testing.T, client client.Client, event expectedEvent) { func waitForRadiusContainerDeleted(t *testing.T, client client.Client, name types.NamespacedName) *deploymentAnnotations { ctx := testcontext.New(t) - logger := t var annotations *deploymentAnnotations require.EventuallyWithTf(t, func(t *assert.CollectT) { - logger.Logf("Fetching Deployment: %+v", name) current := &appsv1.Deployment{} err := client.Get(ctx, name, current) require.NoError(t, err) - logger.Logf("Annotations: %+v", current.Annotations) assert.NotContains(t, current.Annotations, AnnotationRadiusStatus) assert.NotContains(t, current.Annotations, AnnotationRadiusConfigurationHash) }, deploymentTestWaitDuration, deploymentTestWaitInterval, "waiting for state to be Deleting") @@ -694,9 +676,7 @@ func waitForRadiusContainerDeleted(t *testing.T, client client.Client, name type func waitForDeploymentDeleted(t *testing.T, client client.Client, name types.NamespacedName) { ctx := testcontext.New(t) - logger := t require.Eventuallyf(t, func() bool { - logger.Logf("Fetching Deployment: %+v", name) err := client.Get(ctx, name, &appsv1.Deployment{}) return apierrors.IsNotFound(err) }, deploymentTestWaitDuration, deploymentTestWaitInterval, "waiting for deployment to be deleted") diff --git a/pkg/controller/reconciler/deploymentresource_reconciler_test.go b/pkg/controller/reconciler/deploymentresource_reconciler_test.go index 3131a76b19..15a98df05d 100644 --- a/pkg/controller/reconciler/deploymentresource_reconciler_test.go +++ b/pkg/controller/reconciler/deploymentresource_reconciler_test.go @@ -38,7 +38,7 @@ import ( const ( DeploymentResourceTestWaitDuration = time.Second * 10 - DeploymentResourceTestWaitInterval = time.Second * 1 + DeploymentResourceTestWaitInterval = 200 * time.Millisecond DeploymentResourceTestControllerDelayInterval = time.Millisecond * 100 TestDeploymentResourceNamespace = "deploymentresource-basic" @@ -125,16 +125,13 @@ func Test_DeploymentResourceReconciler_Basic(t *testing.T) { func waitForDeploymentResourceStateReady(t *testing.T, client k8sClient.Client, name types.NamespacedName) *radappiov1alpha3.DeploymentResourceStatus { ctx := testcontext.New(t) - logger := t status := &radappiov1alpha3.DeploymentResourceStatus{} require.EventuallyWithTf(t, func(t *assert.CollectT) { - logger.Logf("Fetching DeploymentResource: %+v", name) current := &radappiov1alpha3.DeploymentResource{} err := client.Get(ctx, name, current) require.NoError(t, err) status = ¤t.Status - logger.Logf("DeploymentResource.Status: %+v", current.Status) if assert.Equal(t, radappiov1alpha3.DeploymentResourcePhraseReady, current.Status.Phrase) { assert.Empty(t, current.Status.Operation) } @@ -146,16 +143,13 @@ func waitForDeploymentResourceStateReady(t *testing.T, client k8sClient.Client, func waitForDeploymentResourceStateDeleting(t *testing.T, client k8sClient.Client, name types.NamespacedName, oldOperation *radappiov1alpha3.ResourceOperation) *radappiov1alpha3.DeploymentResourceStatus { ctx := testcontext.New(t) - logger := t status := &radappiov1alpha3.DeploymentResourceStatus{} require.EventuallyWithTf(t, func(t *assert.CollectT) { - logger.Logf("Fetching DeploymentResource: %+v", name) current := &radappiov1alpha3.DeploymentResource{} err := client.Get(ctx, name, current) assert.NoError(t, err) status = ¤t.Status - logger.Logf("DeploymentResource.Status: %+v", current.Status) assert.Equal(t, status.ObservedGeneration, current.Generation, "Status is not updated") if assert.Equal(t, radappiov1alpha3.DeploymentResourcePhraseDeleting, current.Status.Phrase) { @@ -170,17 +164,10 @@ func waitForDeploymentResourceStateDeleting(t *testing.T, client k8sClient.Clien func waitForDeploymentResourceDeleted(t *testing.T, client k8sClient.Client, name types.NamespacedName) { ctx := testcontext.New(t) - logger := t require.Eventuallyf(t, func() bool { - logger.Logf("Fetching DeploymentResource: %+v", name) current := &radappiov1alpha3.DeploymentResource{} err := client.Get(ctx, name, current) - if apierrors.IsNotFound(err) { - return true - } - - logger.Logf("DeploymentResource.Status: %+v", current.Status) - return false + return apierrors.IsNotFound(err) }, DeploymentResourceTestWaitDuration, DeploymentResourceTestWaitInterval, "DeploymentResource still exists") } diff --git a/pkg/controller/reconciler/deploymenttemplate_reconciler_test.go b/pkg/controller/reconciler/deploymenttemplate_reconciler_test.go index 3cbfcb0404..1f67589f22 100644 --- a/pkg/controller/reconciler/deploymenttemplate_reconciler_test.go +++ b/pkg/controller/reconciler/deploymenttemplate_reconciler_test.go @@ -42,7 +42,7 @@ import ( const ( deploymentTemplateTestWaitDuration = time.Second * 10 - deploymentTemplateTestWaitInterval = time.Second * 1 + deploymentTemplateTestWaitInterval = 200 * time.Millisecond deploymentTemplateTestControllerDelayInterval = time.Millisecond * 100 ) @@ -770,10 +770,8 @@ func Test_DeploymentTemplateReconciler_OutputResources(t *testing.T) { func waitForDeploymentTemplateStateUpdating(t *testing.T, client k8sclient.Client, name types.NamespacedName, oldOperation *radappiov1alpha3.ResourceOperation) *radappiov1alpha3.DeploymentTemplateStatus { ctx := testcontext.New(t) - logger := t status := &radappiov1alpha3.DeploymentTemplateStatus{} require.EventuallyWithT(t, func(t *assert.CollectT) { - logger.Logf("Fetching DeploymentTemplate: %+v", name) current := &radappiov1alpha3.DeploymentTemplate{ Status: radappiov1alpha3.DeploymentTemplateStatus{ Phrase: radappiov1alpha3.DeploymentTemplatePhrase(radappiov1alpha3.DeploymentResourcePhraseDeleting), @@ -783,7 +781,6 @@ func waitForDeploymentTemplateStateUpdating(t *testing.T, client k8sclient.Clien require.NoError(t, err) status = ¤t.Status - logger.Logf("DeploymentTemplate.Status: %+v", current.Status) assert.Equal(t, status.ObservedGeneration, current.Generation, "Status is not updated") if assert.Equal(t, radappiov1alpha3.DeploymentTemplatePhraseUpdating, current.Status.Phrase) { @@ -799,16 +796,13 @@ func waitForDeploymentTemplateStateUpdating(t *testing.T, client k8sclient.Clien func waitForDeploymentTemplateStateReady(t *testing.T, client k8sclient.Client, name types.NamespacedName) *radappiov1alpha3.DeploymentTemplateStatus { ctx := testcontext.New(t) - logger := t status := &radappiov1alpha3.DeploymentTemplateStatus{} require.EventuallyWithTf(t, func(t *assert.CollectT) { - logger.Logf("Fetching DeploymentTemplate: %+v", name) current := &radappiov1alpha3.DeploymentTemplate{} err := client.Get(ctx, name, current) require.NoError(t, err) status = ¤t.Status - logger.Logf("DeploymentTemplate.Status: %+v", current.Status) assert.Equal(t, status.ObservedGeneration, current.Generation, "Status is not updated") if assert.Equal(t, radappiov1alpha3.DeploymentTemplatePhraseReady, current.Status.Phrase) { @@ -822,16 +816,13 @@ func waitForDeploymentTemplateStateReady(t *testing.T, client k8sclient.Client, func waitForDeploymentTemplateStateDeleting(t *testing.T, client k8sclient.Client, name types.NamespacedName) *radappiov1alpha3.DeploymentTemplateStatus { ctx := testcontext.New(t) - logger := t status := &radappiov1alpha3.DeploymentTemplateStatus{} require.EventuallyWithTf(t, func(t *assert.CollectT) { - logger.Logf("Fetching DeploymentTemplate: %+v", name) current := &radappiov1alpha3.DeploymentTemplate{} err := client.Get(ctx, name, current) assert.NoError(t, err) status = ¤t.Status - logger.Logf("DeploymentTemplate.Status: %+v", current.Status) assert.Equal(t, status.ObservedGeneration, current.Generation, "Status is not updated") assert.Equal(t, radappiov1alpha3.DeploymentTemplatePhraseDeleting, current.Status.Phrase) @@ -843,17 +834,10 @@ func waitForDeploymentTemplateStateDeleting(t *testing.T, client k8sclient.Clien func waitForDeploymentTemplateStateDeleted(t *testing.T, client k8sclient.Client, name types.NamespacedName) { ctx := testcontext.New(t) - logger := t require.Eventuallyf(t, func() bool { - logger.Logf("Fetching DeploymentTemplate: %+v", name) current := &radappiov1alpha3.DeploymentTemplate{} err := client.Get(ctx, name, current) - if apierrors.IsNotFound(err) { - return true - } - - logger.Logf("DeploymentTemplate.Status: %+v", current.Status) - return false + return apierrors.IsNotFound(err) }, deploymentTemplateTestWaitDuration, deploymentTemplateTestWaitInterval, "DeploymentTemplate still exists") } diff --git a/pkg/controller/reconciler/shared_test.go b/pkg/controller/reconciler/shared_test.go index 6990f7adbe..395acbf904 100644 --- a/pkg/controller/reconciler/shared_test.go +++ b/pkg/controller/reconciler/shared_test.go @@ -39,7 +39,7 @@ import ( const ( recipeTestWaitDuration = time.Second * 10 - recipeTestWaitInterval = time.Second * 1 + recipeTestWaitInterval = 200 * time.Millisecond recipeTestControllerDelayInterval = time.Millisecond * 100 ) @@ -69,16 +69,13 @@ func makeRecipe(name types.NamespacedName, resourceType string) *radappiov1alpha func waitForRecipeStateUpdating(t *testing.T, client client.Client, name types.NamespacedName, oldOperation *radappiov1alpha3.ResourceOperation) *radappiov1alpha3.RecipeStatus { ctx := testcontext.New(t) - logger := t status := &radappiov1alpha3.RecipeStatus{} require.EventuallyWithT(t, func(t *assert.CollectT) { - logger.Logf("Fetching Recipe: %+v", name) current := &radappiov1alpha3.Recipe{} err := client.Get(ctx, name, current) require.NoError(t, err) status = ¤t.Status - logger.Logf("Recipe.Status: %+v", current.Status) assert.Equal(t, status.ObservedGeneration, current.Generation, "Status is not updated") if assert.Equal(t, radappiov1alpha3.PhraseUpdating, current.Status.Phrase) { @@ -94,16 +91,13 @@ func waitForRecipeStateUpdating(t *testing.T, client client.Client, name types.N func waitForRecipeStateReady(t *testing.T, client client.Client, name types.NamespacedName) *radappiov1alpha3.RecipeStatus { ctx := testcontext.New(t) - logger := t status := &radappiov1alpha3.RecipeStatus{} require.EventuallyWithTf(t, func(t *assert.CollectT) { - logger.Logf("Fetching Recipe: %+v", name) current := &radappiov1alpha3.Recipe{} err := client.Get(ctx, name, current) require.NoError(t, err) status = ¤t.Status - logger.Logf("Recipe.Status: %+v", current.Status) assert.Equal(t, status.ObservedGeneration, current.Generation, "Status is not updated") if assert.Equal(t, radappiov1alpha3.PhraseReady, current.Status.Phrase) { @@ -117,16 +111,13 @@ func waitForRecipeStateReady(t *testing.T, client client.Client, name types.Name func waitForRecipeStateDeleting(t *testing.T, client client.Client, name types.NamespacedName, oldOperation *radappiov1alpha3.ResourceOperation) *radappiov1alpha3.RecipeStatus { ctx := testcontext.New(t) - logger := t status := &radappiov1alpha3.RecipeStatus{} require.EventuallyWithTf(t, func(t *assert.CollectT) { - logger.Logf("Fetching Recipe: %+v", name) current := &radappiov1alpha3.Recipe{} err := client.Get(ctx, name, current) assert.NoError(t, err) status = ¤t.Status - logger.Logf("Recipe.Status: %+v", current.Status) assert.Equal(t, status.ObservedGeneration, current.Generation, "Status is not updated") if assert.Equal(t, radappiov1alpha3.PhraseDeleting, current.Status.Phrase) { @@ -141,17 +132,10 @@ func waitForRecipeStateDeleting(t *testing.T, client client.Client, name types.N func waitForRecipeDeleted(t *testing.T, client client.Client, name types.NamespacedName) { ctx := testcontext.New(t) - logger := t require.Eventuallyf(t, func() bool { - logger.Logf("Fetching Recipe: %+v", name) current := &radappiov1alpha3.Recipe{} err := client.Get(ctx, name, current) - if apierrors.IsNotFound(err) { - return true - } - - logger.Logf("Recipe.Status: %+v", current.Status) - return false + return apierrors.IsNotFound(err) }, recipeTestWaitDuration, recipeTestWaitInterval, "recipe still exists") } diff --git a/pkg/ucp/integrationtests/resourceproviders/resourceproviders_test.go b/pkg/ucp/integrationtests/resourceproviders/resourceproviders_test.go index a44b6fcd1d..58b70cedb6 100644 --- a/pkg/ucp/integrationtests/resourceproviders/resourceproviders_test.go +++ b/pkg/ucp/integrationtests/resourceproviders/resourceproviders_test.go @@ -88,11 +88,21 @@ func Test_ResourceProvider_CascadingDelete(t *testing.T) { deleteResourceProvider(server) // The resource type should be gone now. + require.Eventually(t, func() bool { + response := server.MakeRequest(http.MethodGet, resourceTypeURL, nil) + return response.Raw.StatusCode == http.StatusNotFound + }, 10*time.Second, 100*time.Millisecond) + response := server.MakeRequest(http.MethodGet, resourceTypeURL, nil) response.EqualsErrorCode(404, "NotFound") require.Equal(t, resourceTypeID, response.Error.Error.Target) // The location should be gone now. + require.Eventually(t, func() bool { + response := server.MakeRequest(http.MethodGet, locationURL, nil) + return response.Raw.StatusCode == http.StatusNotFound + }, 10*time.Second, 100*time.Millisecond) + response = server.MakeRequest(http.MethodGet, locationURL, nil) response.EqualsErrorCode(404, "NotFound") require.Equal(t, locationID, response.Error.Error.Target) diff --git a/pkg/ucp/integrationtests/resourceproviders/resourcetypes_test.go b/pkg/ucp/integrationtests/resourceproviders/resourcetypes_test.go index 6db34e64ce..af0145349d 100644 --- a/pkg/ucp/integrationtests/resourceproviders/resourcetypes_test.go +++ b/pkg/ucp/integrationtests/resourceproviders/resourcetypes_test.go @@ -19,6 +19,7 @@ package resourceproviders import ( "net/http" "testing" + "time" "github.com/radius-project/radius/pkg/ucp/testhost" "github.com/stretchr/testify/require" @@ -81,6 +82,11 @@ func Test_ResourceType_CascadingDelete(t *testing.T) { deleteResourceType(server) // The API version should be gone now. + require.Eventually(t, func() bool { + response := server.MakeRequest(http.MethodGet, apiVersionURL, nil) + return response.Raw.StatusCode == http.StatusNotFound + }, 10*time.Second, 100*time.Millisecond) + response := server.MakeRequest(http.MethodGet, apiVersionURL, nil) response.EqualsErrorCode(404, "NotFound") require.Equal(t, apiVersionID, response.Error.Error.Target) diff --git a/test/ucp/kubeenv/testenv.go b/test/ucp/kubeenv/testenv.go index 04ad83c807..5430f6b076 100644 --- a/test/ucp/kubeenv/testenv.go +++ b/test/ucp/kubeenv/testenv.go @@ -22,6 +22,7 @@ import ( "fmt" "os" "os/exec" + "strings" ucpv1alpha1 "github.com/radius-project/radius/pkg/components/database/apiserverstore/api/ucp.dev/v1alpha1" v1 "k8s.io/api/core/v1" @@ -83,7 +84,11 @@ func getKubeAssetsDir() (string, error) { if err != nil { return "", fmt.Errorf("failed to call setup-envtest to find path: %w", err) } else { - return out.String(), err + assetsPath := strings.TrimSpace(out.String()) + if assetsPath == "" { + return "", fmt.Errorf("failed to call setup-envtest to find path: empty output") + } + return assetsPath, nil } } diff --git a/test/ucp/queuetest/shared.go b/test/ucp/queuetest/shared.go index 2bd0214871..6ee70d7441 100644 --- a/test/ucp/queuetest/shared.go +++ b/test/ucp/queuetest/shared.go @@ -30,7 +30,7 @@ import ( ) const ( - TestMessageLockTime = time.Duration(1) * time.Second + TestMessageLockTime = 200 * time.Millisecond pollingInterval = time.Duration(100) * time.Millisecond