From 33414a7cc469bfb6dbb5e25182864226fb9722c1 Mon Sep 17 00:00:00 2001 From: Jian Zhang Date: Tue, 2 Dec 2025 09:14:53 +0800 Subject: [PATCH] Fix testCatalogName conflict in parallel e2e tests --- test/e2e/cluster_extension_install_test.go | 15 +++++++++++---- test/helpers/helpers.go | 18 +++++++++++++----- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/test/e2e/cluster_extension_install_test.go b/test/e2e/cluster_extension_install_test.go index ab0bf48b1..b3380ff0f 100644 --- a/test/e2e/cluster_extension_install_test.go +++ b/test/e2e/cluster_extension_install_test.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "os" + "slices" "testing" "time" @@ -197,7 +198,8 @@ func TestClusterExtensionInstallRegistryMultipleBundles(t *testing.T) { t.Log("When a cluster extension is installed from a catalog") clusterExtension, extensionCatalog, sa, ns := TestInit(t) - extraCatalog, err := CreateTestCatalog(context.Background(), "extra-test-catalog", os.Getenv(testCatalogRefEnvVar)) + extraCatalogName := fmt.Sprintf("extra-test-catalog-%s", rand.String(8)) + extraCatalog, err := CreateTestCatalog(context.Background(), extraCatalogName, os.Getenv(testCatalogRefEnvVar)) require.NoError(t, err) defer TestCleanup(t, extensionCatalog, clusterExtension, sa, ns) @@ -238,7 +240,11 @@ func TestClusterExtensionInstallRegistryMultipleBundles(t *testing.T) { require.NotNil(ct, cond) require.Equal(ct, metav1.ConditionTrue, cond.Status) require.Equal(ct, ocv1.ReasonRetrying, cond.Reason) - require.Contains(ct, cond.Message, "in multiple catalogs with the same priority [extra-test-catalog test-catalog]") + // Catalog names are sorted alphabetically in the error message + catalogs := []string{extensionCatalog.Name, extraCatalog.Name} + slices.Sort(catalogs) + expectedMessage := fmt.Sprintf("in multiple catalogs with the same priority %v", catalogs) + require.Contains(ct, cond.Message, expectedMessage) }, pollDuration, pollInterval) } @@ -441,7 +447,7 @@ func TestClusterExtensionInstallReResolvesWhenCatalogIsPatched(t *testing.T) { // patch imageRef tag on test-catalog image with v2 image t.Log("By patching the catalog ImageRef to point to the v2 catalog") updatedCatalogImage := fmt.Sprintf("%s/e2e/test-catalog:v2", os.Getenv("CLUSTER_REGISTRY_HOST")) - err := patchTestCatalog(context.Background(), testCatalogName, updatedCatalogImage) + err := patchTestCatalog(context.Background(), extensionCatalog.Name, updatedCatalogImage) require.NoError(t, err) require.EventuallyWithT(t, func(ct *assert.CollectT) { require.NoError(ct, c.Get(context.Background(), types.NamespacedName{Name: extensionCatalog.Name}, extensionCatalog)) @@ -474,8 +480,9 @@ func TestClusterExtensionInstallReResolvesWhenNewCatalog(t *testing.T) { require.NoError(t, err) // create a test-catalog with latest image tag + catalogName := fmt.Sprintf("test-catalog-%s", rand.String(8)) latestCatalogImage := fmt.Sprintf("%s/e2e/test-catalog:latest", os.Getenv("CLUSTER_REGISTRY_HOST")) - extensionCatalog, err := CreateTestCatalog(context.Background(), testCatalogName, latestCatalogImage) + extensionCatalog, err := CreateTestCatalog(context.Background(), catalogName, latestCatalogImage) require.NoError(t, err) clusterExtensionName := fmt.Sprintf("clusterextension-%s", rand.String(8)) clusterExtension := &ocv1.ClusterExtension{ diff --git a/test/helpers/helpers.go b/test/helpers/helpers.go index 49ebeaab6..af142c6e3 100644 --- a/test/helpers/helpers.go +++ b/test/helpers/helpers.go @@ -218,6 +218,7 @@ func TestInit(t *testing.T) (*ocv1.ClusterExtension, *ocv1.ClusterCatalog, *core func TestInitClusterExtensionClusterCatalog(t *testing.T) (*ocv1.ClusterExtension, *ocv1.ClusterCatalog) { ceName := fmt.Sprintf("clusterextension-%s", rand.String(8)) + catalogName := fmt.Sprintf("test-catalog-%s", rand.String(8)) ce := &ocv1.ClusterExtension{ ObjectMeta: metav1.ObjectMeta{ @@ -225,10 +226,10 @@ func TestInitClusterExtensionClusterCatalog(t *testing.T) (*ocv1.ClusterExtensio }, } - cc, err := CreateTestCatalog(context.Background(), testCatalogName, os.Getenv(testCatalogRefEnvVar)) + cc, err := CreateTestCatalog(context.Background(), catalogName, os.Getenv(testCatalogRefEnvVar)) require.NoError(t, err) - ValidateCatalogUnpack(t) + ValidateCatalogUnpackWithName(t, catalogName) return ce, cc } @@ -250,11 +251,18 @@ func TestInitServiceAccountNamespace(t *testing.T, clusterExtensionName string) return sa, ns } +// ValidateCatalogUnpack validates that the test catalog with the default name has unpacked successfully. +// Deprecated: Use ValidateCatalogUnpackWithName for tests that use unique catalog names. func ValidateCatalogUnpack(t *testing.T) { + ValidateCatalogUnpackWithName(t, testCatalogName) +} + +// ValidateCatalogUnpackWithName validates that a catalog with the given name has unpacked successfully. +func ValidateCatalogUnpackWithName(t *testing.T, catalogName string) { catalog := &ocv1.ClusterCatalog{} t.Log("Ensuring ClusterCatalog has Status.Condition of Progressing with a status == True and reason == Succeeded") require.EventuallyWithT(t, func(ct *assert.CollectT) { - err := c.Get(context.Background(), types.NamespacedName{Name: testCatalogName}, catalog) + err := c.Get(context.Background(), types.NamespacedName{Name: catalogName}, catalog) require.NoError(ct, err) cond := apimeta.FindStatusCondition(catalog.Status.Conditions, ocv1.TypeProgressing) require.NotNil(ct, cond) @@ -265,11 +273,11 @@ func ValidateCatalogUnpack(t *testing.T) { t.Log("Checking that catalog has the expected metadata label") require.NotNil(t, catalog.Labels) require.Contains(t, catalog.Labels, "olm.operatorframework.io/metadata.name") - require.Equal(t, testCatalogName, catalog.Labels["olm.operatorframework.io/metadata.name"]) + require.Equal(t, catalogName, catalog.Labels["olm.operatorframework.io/metadata.name"]) t.Log("Ensuring ClusterCatalog has Status.Condition of Type = Serving with status == True") require.EventuallyWithT(t, func(ct *assert.CollectT) { - err := c.Get(context.Background(), types.NamespacedName{Name: testCatalogName}, catalog) + err := c.Get(context.Background(), types.NamespacedName{Name: catalogName}, catalog) require.NoError(ct, err) cond := apimeta.FindStatusCondition(catalog.Status.Conditions, ocv1.TypeServing) require.NotNil(ct, cond)