From e525aeed182d5a84f34b3b0b75f32810ccabe0d0 Mon Sep 17 00:00:00 2001 From: Paul Meyer <49727155+katexochen@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:58:16 +0200 Subject: [PATCH] e2e: platform-dependent timout factor Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com> --- e2e/getdents/getdents_test.go | 2 +- e2e/internal/contrasttest/contrasttest.go | 13 +++++++++++++ e2e/openssl/openssl_test.go | 10 +++++----- e2e/policy/policy_test.go | 2 +- e2e/regression/regression_test.go | 2 +- e2e/servicemesh/servicemesh_test.go | 8 ++++---- e2e/workloadsecret/workloadsecret_test.go | 10 +++++----- 7 files changed, 30 insertions(+), 17 deletions(-) diff --git a/e2e/getdents/getdents_test.go b/e2e/getdents/getdents_test.go index 75b548856..c90158b99 100644 --- a/e2e/getdents/getdents_test.go +++ b/e2e/getdents/getdents_test.go @@ -73,7 +73,7 @@ func TestGetDEnts(t *testing.T) { t.Run("call find on large folder", func(t *testing.T) { require := require.New(t) - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), ct.FactorPlatformTimeout(30*time.Second)) defer cancel() require.NoError(ct.Kubeclient.WaitFor(ctx, kubeclient.Deployment{}, ct.Namespace, getdent)) diff --git a/e2e/internal/contrasttest/contrasttest.go b/e2e/internal/contrasttest/contrasttest.go index 71753a5a6..77684d31b 100644 --- a/e2e/internal/contrasttest/contrasttest.go +++ b/e2e/internal/contrasttest/contrasttest.go @@ -342,6 +342,19 @@ func (ct *ContrastTest) runAgainstCoordinator(ctx context.Context, cmd *cobra.Co }) } +// FactorPlatformTimeout returns a timeout that is adjusted for the platform. +// Baseline is AKS. +func (ct *ContrastTest) FactorPlatformTimeout(timeout time.Duration) time.Duration { + switch ct.Platform { + case platforms.AKSCloudHypervisorSNP: // AKS defined is the baseline + return timeout + case platforms.K3sQEMUSNP, platforms.K3sQEMUTDX, platforms.RKE2QEMUTDX: + return 2 * timeout + default: + return timeout + } +} + func makeNamespace(t *testing.T) string { buf := make([]byte, 4) re := regexp.MustCompile("[a-z0-9-]+") diff --git a/e2e/openssl/openssl_test.go b/e2e/openssl/openssl_test.go index ffc844360..03b34568b 100644 --- a/e2e/openssl/openssl_test.go +++ b/e2e/openssl/openssl_test.go @@ -68,7 +68,7 @@ func TestOpenSSL(t *testing.T) { require.True(t, t.Run("contrast verify", ct.Verify), "contrast verify needs to succeed for subsequent tests") t.Run("check coordinator metrics endpoint", func(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), ct.FactorPlatformTimeout(1*time.Minute)) defer cancel() require := require.New(t) @@ -93,7 +93,7 @@ func TestOpenSSL(t *testing.T) { "root CA cert": ct.RootCACert(), } { t.Run("go dial frontend with "+cert, func(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), ct.FactorPlatformTimeout(1*time.Minute)) defer cancel() require := require.New(t) @@ -115,7 +115,7 @@ func TestOpenSSL(t *testing.T) { // This test verifies that the certificates minted by the coordinator are accepted by OpenSSL in server and client mode. require := require.New(t) - ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), ct.FactorPlatformTimeout(1*time.Minute)) defer cancel() c := kubeclient.NewForTest(t) @@ -136,7 +136,7 @@ func TestOpenSSL(t *testing.T) { t.Run(fmt.Sprintf("certificate rotation and %s restart", deploymentToRestart), func(t *testing.T) { require := require.New(t) - ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), ct.FactorPlatformTimeout(1*time.Minute)) defer cancel() c := kubeclient.NewForTest(t) @@ -195,7 +195,7 @@ func TestOpenSSL(t *testing.T) { t.Run("coordinator recovery", func(t *testing.T) { require := require.New(t) - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) // Already long timeout, not using ct.FactorPlatformTimeout. defer cancel() c := kubeclient.NewForTest(t) diff --git a/e2e/policy/policy_test.go b/e2e/policy/policy_test.go index 4d20ca4c4..773a6fe62 100644 --- a/e2e/policy/policy_test.go +++ b/e2e/policy/policy_test.go @@ -68,7 +68,7 @@ func TestPolicy(t *testing.T) { t.Run("pod cannot join after it was removed from the manifest", func(t *testing.T) { require := require.New(t) - ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), ct.FactorPlatformTimeout(1*time.Minute)) defer cancel() c := kubeclient.NewForTest(t) diff --git a/e2e/regression/regression_test.go b/e2e/regression/regression_test.go index 2f875c2ac..2c52a1798 100644 --- a/e2e/regression/regression_test.go +++ b/e2e/regression/regression_test.go @@ -60,7 +60,7 @@ func TestRegression(t *testing.T) { require := require.New(t) c := kubeclient.NewForTest(t) - ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) // Already long timeout, not using ct.FactorPlatformTimeout. defer cancel() yaml, err := os.ReadFile(yamlDir + file.Name()) diff --git a/e2e/servicemesh/servicemesh_test.go b/e2e/servicemesh/servicemesh_test.go index ae57d1aea..8f180f134 100644 --- a/e2e/servicemesh/servicemesh_test.go +++ b/e2e/servicemesh/servicemesh_test.go @@ -62,7 +62,7 @@ func TestIngressEgress(t *testing.T) { require.True(t, t.Run("deployments become available", func(t *testing.T) { require := require.New(t) - ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), ct.FactorPlatformTimeout(1*time.Minute)) defer cancel() require.NoError(ct.Kubeclient.WaitFor(ctx, kubeclient.Deployment{}, ct.Namespace, "vote-bot")) @@ -79,7 +79,7 @@ func TestIngressEgress(t *testing.T) { t.Run("go dial web with ca "+certFile, func(t *testing.T) { require := require.New(t) - ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), ct.FactorPlatformTimeout(1*time.Minute)) defer cancel() require.NoError(ct.Kubeclient.WithForwardedPort(ctx, ct.Namespace, "port-forwarder-web-svc", "443", func(addr string) error { @@ -103,7 +103,7 @@ func TestIngressEgress(t *testing.T) { t.Run("client certificates are required if not explicitly disabled", func(t *testing.T) { require := require.New(t) - ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), ct.FactorPlatformTimeout(1*time.Minute)) defer cancel() c := kubeclient.NewForTest(t) @@ -133,7 +133,7 @@ func TestIngressEgress(t *testing.T) { t.Run("admin interface is available", func(t *testing.T) { require := require.New(t) - ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), ct.FactorPlatformTimeout(1*time.Minute)) defer cancel() c := kubeclient.NewForTest(t) diff --git a/e2e/workloadsecret/workloadsecret_test.go b/e2e/workloadsecret/workloadsecret_test.go index 089e448e8..6d5a830be 100644 --- a/e2e/workloadsecret/workloadsecret_test.go +++ b/e2e/workloadsecret/workloadsecret_test.go @@ -61,7 +61,7 @@ func TestWorkloadSecrets(t *testing.T) { require.True(t, t.Run("deployments become available", func(t *testing.T) { require := require.New(t) - ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), ct.FactorPlatformTimeout(1*time.Minute)) defer cancel() require.NoError(ct.Kubeclient.WaitFor(ctx, kubeclient.Deployment{}, ct.Namespace, "vote-bot")) @@ -74,7 +74,7 @@ func TestWorkloadSecrets(t *testing.T) { require.True(t, t.Run("scale web deployment to 2 pods", func(t *testing.T) { require := require.New(t) - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), ct.FactorPlatformTimeout(30*time.Second)) defer cancel() require.NoError(ct.Kubeclient.ScaleDeployment(ctx, ct.Namespace, "web", 2)) @@ -86,7 +86,7 @@ func TestWorkloadSecrets(t *testing.T) { t.Run("workload secret seed exists", func(t *testing.T) { require := require.New(t) - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), ct.FactorPlatformTimeout(30*time.Second)) defer cancel() webPods, err = ct.Kubeclient.PodsFromDeployment(ctx, ct.Namespace, "web") @@ -104,7 +104,7 @@ func TestWorkloadSecrets(t *testing.T) { t.Run("workload secret seed is the same between pods in the same deployment", func(t *testing.T) { require := require.New(t) - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), ct.FactorPlatformTimeout(30*time.Second)) defer cancel() stdout, stderr, err := ct.Kubeclient.Exec(ctx, ct.Namespace, webPods[1].Name, []string{"/bin/sh", "-c", "cat /contrast/secrets/workload-secret-seed"}) @@ -120,7 +120,7 @@ func TestWorkloadSecrets(t *testing.T) { t.Run("workload secret seeds differ between deployments by default", func(t *testing.T) { require := require.New(t) - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), ct.FactorPlatformTimeout(30*time.Second)) defer cancel() emojiPods, err := ct.Kubeclient.PodsFromDeployment(ctx, ct.Namespace, "emoji")