From 0d8793015122254dede9ba5d268d2d8e60303bca Mon Sep 17 00:00:00 2001 From: matttrach Date: Wed, 15 Oct 2025 12:51:59 -0500 Subject: [PATCH] fix: reduce test concurrency Signed-off-by: matttrach --- .envrc | 7 +++-- .github/workflows/release.yaml | 2 ++ test/tests/downstream/basic_test.go | 2 +- test/tests/downstream/splitrole_test.go | 2 +- test/tests/one/basic_test.go | 2 +- test/tests/prod/basic_test.go | 8 ++--- test/tests/three/basic_test.go | 14 +++++---- test/tests/three/state_test.go | 40 ++++++++++++++----------- 8 files changed, 45 insertions(+), 32 deletions(-) diff --git a/.envrc b/.envrc index 7528c4b..ff71ed0 100644 --- a/.envrc +++ b/.envrc @@ -31,9 +31,12 @@ if ! which "$0" | grep -q nix; then export NIX_PROFILE="$profile" print 'Updating Nix Cache...' - nf flake update + if ! nf flake update; then + print 'Failed to update Nix flake, continuing with existing cache...' + git checkout flake.lock + fi - echo 'Installing Nix Profile...' + print 'Installing Nix Profile...' nf profile install . --profile "$profile" nf profile list --profile "$profile" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 38045fd..b520ed2 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -161,6 +161,7 @@ jobs: needs: - release - test_TestOneBasic + - test_TestProdBasic if: needs.release.outputs.release_pr runs-on: ubuntu-latest steps: @@ -250,6 +251,7 @@ jobs: - test_TestOneBasic - test_TestProdBasic - test_TestThreeBasic + - test_TestDownstreamBasic if: needs.release.outputs.release_pr runs-on: ubuntu-latest steps: diff --git a/test/tests/downstream/basic_test.go b/test/tests/downstream/basic_test.go index dafb3e0..3ce9f0d 100644 --- a/test/tests/downstream/basic_test.go +++ b/test/tests/downstream/basic_test.go @@ -97,7 +97,7 @@ func TestDownstreamBasic(t *testing.T) { "KUBECONFIG": testDir + "/kubeconfig", "KUBE_CONFIG_PATH": testDir, "TF_CLI_ARGS_plan": "-no-color -state=" + testDir + "/tfstate", - "TF_CLI_ARGS_apply": "-no-color -state=" + testDir + "/tfstate", + "TF_CLI_ARGS_apply": "-no-color -state=" + testDir + "/tfstate -parallelism=5", "TF_CLI_ARGS_destroy": "-no-color -state=" + testDir + "/tfstate", "TF_CLI_ARGS_output": "-no-color -state=" + testDir + "/tfstate", }, diff --git a/test/tests/downstream/splitrole_test.go b/test/tests/downstream/splitrole_test.go index c07d2bf..1562c36 100644 --- a/test/tests/downstream/splitrole_test.go +++ b/test/tests/downstream/splitrole_test.go @@ -99,7 +99,7 @@ func TestDownstreamSplitrole(t *testing.T) { "KUBECONFIG": testDir + "/kubeconfig", "KUBE_CONFIG_PATH": testDir, "TF_CLI_ARGS_plan": "-no-color -state=" + testDir + "/tfstate", - "TF_CLI_ARGS_apply": "-no-color -state=" + testDir + "/tfstate", + "TF_CLI_ARGS_apply": "-no-color -state=" + testDir + "/tfstate -parallelism=5", "TF_CLI_ARGS_destroy": "-no-color -state=" + testDir + "/tfstate", "TF_CLI_ARGS_output": "-no-color -state=" + testDir + "/tfstate", }, diff --git a/test/tests/one/basic_test.go b/test/tests/one/basic_test.go index 0c2fa67..ec6169f 100644 --- a/test/tests/one/basic_test.go +++ b/test/tests/one/basic_test.go @@ -89,7 +89,7 @@ func TestOneBasic(t *testing.T) { "TF_DATA_DIR": testDir, "TF_IN_AUTOMATION": "1", "TF_CLI_ARGS_plan": "-no-color -state=" + testDir + "/tfstate", - "TF_CLI_ARGS_apply": "-no-color -state=" + testDir + "/tfstate", + "TF_CLI_ARGS_apply": "-no-color -state=" + testDir + "/tfstate -parallelism=5", "TF_CLI_ARGS_destroy": "-no-color -state=" + testDir + "/tfstate", "TF_CLI_ARGS_output": "-no-color -state=" + testDir + "/tfstate", }, diff --git a/test/tests/prod/basic_test.go b/test/tests/prod/basic_test.go index 9a20451..78861e7 100644 --- a/test/tests/prod/basic_test.go +++ b/test/tests/prod/basic_test.go @@ -19,7 +19,7 @@ func TestProdBasic(t *testing.T) { accessKey := util.GetAwsAccessKey() secretKey := util.GetAwsSecretKey() sessionToken := util.GetAwsSessionToken() - directory := "prod" + directory := "prod" owner := "terraform-ci@suse.com" util.SetAcmeServer() @@ -89,15 +89,15 @@ func TestProdBasic(t *testing.T) { "aws_secret_access_key": secretKey, "aws_session_token": sessionToken, "aws_region": region, - }, + }, // Environment variables to set when running Terraform EnvVars: map[string]string{ - "AWS_DEFAULT_REGION": region, + "AWS_DEFAULT_REGION": region, "AWS_REGION": region, "TF_DATA_DIR": testDir, "TF_IN_AUTOMATION": "1", "TF_CLI_ARGS_plan": "-no-color -state=" + testDir + "/tfstate", - "TF_CLI_ARGS_apply": "-no-color -state=" + testDir + "/tfstate", + "TF_CLI_ARGS_apply": "-no-color -state=" + testDir + "/tfstate -parallelism=5", "TF_CLI_ARGS_destroy": "-no-color -state=" + testDir + "/tfstate", "TF_CLI_ARGS_output": "-no-color -state=" + testDir + "/tfstate", }, diff --git a/test/tests/three/basic_test.go b/test/tests/three/basic_test.go index 46e7006..a1207f4 100644 --- a/test/tests/three/basic_test.go +++ b/test/tests/three/basic_test.go @@ -92,11 +92,15 @@ func TestThreeBasic(t *testing.T) { }, // Environment variables to set when running Terraform EnvVars: map[string]string{ - "AWS_DEFAULT_REGION": region, - "AWS_REGION": region, - "TF_DATA_DIR": testDir, - "TF_IN_AUTOMATION": "1", - "TF_CLI_ARGS_init": "-backend-config=\"bucket=" + strings.ToLower(id) + "\"", + "AWS_DEFAULT_REGION": region, + "AWS_REGION": region, + "TF_DATA_DIR": testDir, + "TF_IN_AUTOMATION": "1", + "TF_CLI_ARGS_init": "-backend-config=\"bucket=" + strings.ToLower(id) + "\"", + "TF_CLI_ARGS_plan": "-no-color", // using remote state from storage backend + "TF_CLI_ARGS_apply": "-no-color -parallelism=5", + "TF_CLI_ARGS_destroy": "-no-color", + "TF_CLI_ARGS_output": "-no-color", }, RetryableTerraformErrors: util.GetRetryableTerraformErrors(), NoColor: true, diff --git a/test/tests/three/state_test.go b/test/tests/three/state_test.go index b389bf9..0dab18c 100644 --- a/test/tests/three/state_test.go +++ b/test/tests/three/state_test.go @@ -18,16 +18,16 @@ func TestThreeState(t *testing.T) { t.Parallel() util.SetAcmeServer() - id := util.GetId() - region := util.GetRegion() - directory := "three" - owner := "terraform-ci@suse.com" + id := util.GetId() + region := util.GetRegion() + directory := "three" + owner := "terraform-ci@suse.com" repoRoot, err := filepath.Abs(g.GetRepoRoot(t)) if err != nil { t.Fatalf("Error getting git root directory: %v", err) } exampleDir := repoRoot + "/examples/" + directory - testDir := repoRoot + "/test/tests/data/" + id + testDir := repoRoot + "/test/tests/data/" + id err = util.CreateTestDirectories(t, id) if err != nil { @@ -92,11 +92,15 @@ func TestThreeState(t *testing.T) { }, // Environment variables to set when running Terraform EnvVars: map[string]string{ - "AWS_DEFAULT_REGION": region, - "AWS_REGION": region, - "TF_DATA_DIR": testDir, - "TF_IN_AUTOMATION": "1", - "TF_CLI_ARGS_init": "-backend-config=\"bucket=" + strings.ToLower(id) + "\"", + "AWS_DEFAULT_REGION": region, + "AWS_REGION": region, + "TF_DATA_DIR": testDir, + "TF_IN_AUTOMATION": "1", + "TF_CLI_ARGS_init": "-backend-config=\"bucket=" + strings.ToLower(id) + "\"", + "TF_CLI_ARGS_plan": "-no-color", // using remote state from storage backend + "TF_CLI_ARGS_apply": "-no-color -parallelism=5", + "TF_CLI_ARGS_destroy": "-no-color", + "TF_CLI_ARGS_output": "-no-color", }, RetryableTerraformErrors: util.GetRetryableTerraformErrors(), NoColor: true, @@ -116,7 +120,7 @@ func TestThreeState(t *testing.T) { util.CheckReady(t, testDir+"/kubeconfig") util.CheckRunning(t, testDir+"/kubeconfig") - os.RemoveAll(testDir) + os.RemoveAll(testDir) err = util.CreateTestDirectories(t, id) if err != nil { t.Log("Test failed, tearing down...") @@ -125,16 +129,16 @@ func TestThreeState(t *testing.T) { t.Fatalf("Error creating cluster: %s", err) } - // Running the apply again should re-create everything from state in S3 - // This should only recreate the files, the resources should be untouched + // Running the apply again should re-create everything from state in S3 + // This should only recreate the files, the resources should be untouched err = os.WriteFile(testDir+"/id_rsa", []byte(keyPair.KeyPair.PrivateKey), 0600) if err != nil { t.Log("Test failed, tearing down...") util.GetErrorLogs(t, testDir+"/kubeconfig") util.Teardown(t, testDir, exampleDir, newTfOptions, keyPair, sshAgent) t.Fatalf("Error creating cluster: %s", err) - } - _, err = terraform.InitAndApplyE(t, terraformOptions) + } + _, err = terraform.InitAndApplyE(t, terraformOptions) if err != nil { t.Log("Test failed, tearing down...") util.GetErrorLogs(t, testDir+"/kubeconfig") @@ -144,8 +148,8 @@ func TestThreeState(t *testing.T) { util.CheckReady(t, testDir+"/kubeconfig") util.CheckRunning(t, testDir+"/kubeconfig") - // Running the apply again should not change anything - _, err = terraform.InitAndApplyE(t, terraformOptions) + // Running the apply again should not change anything + _, err = terraform.InitAndApplyE(t, terraformOptions) if err != nil { t.Log("Test failed, tearing down...") util.GetErrorLogs(t, testDir+"/kubeconfig") @@ -155,7 +159,7 @@ func TestThreeState(t *testing.T) { util.CheckReady(t, testDir+"/kubeconfig") util.CheckRunning(t, testDir+"/kubeconfig") - if t.Failed() { + if t.Failed() { t.Log("Test failed...") } else { t.Log("Test passed...")