Skip to content

Commit

Permalink
e2e: platform-dependent timeout factor
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Meyer <[email protected]>
  • Loading branch information
katexochen committed Aug 30, 2024
1 parent 4c77c03 commit bd6172a
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion e2e/getdents/getdents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
13 changes: 13 additions & 0 deletions e2e/internal/contrasttest/contrasttest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-]+")
Expand Down
10 changes: 5 additions & 5 deletions e2e/openssl/openssl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion e2e/policy/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion e2e/regression/regression_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
8 changes: 4 additions & 4 deletions e2e/servicemesh/servicemesh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions e2e/workloadsecret/workloadsecret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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))
Expand All @@ -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")
Expand All @@ -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"})
Expand All @@ -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")
Expand Down

0 comments on commit bd6172a

Please sign in to comment.