Skip to content

Commit

Permalink
Feat: run harness parallel tests in parallel (#676)
Browse files Browse the repository at this point in the history
* Revert "Revert "Feat: run harness tests in parallel (#669)" (#670)"

This reverts commit e2f3f6e.

* updated integration tests to avoid race conditions
  • Loading branch information
TomerHeber committed Jul 11, 2023
1 parent cb67719 commit 33c54a8
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 23 deletions.
5 changes: 5 additions & 0 deletions env0/data_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func dataTemplate() *schema.Resource {
Optional: true,
ExactlyOneOf: []string{"name", "id"},
},
"description": {
Type: schema.TypeString,
Description: "description for the template",
Computed: true,
},
"repository": {
Type: schema.TypeString,
Description: "template source code repository url",
Expand Down
26 changes: 19 additions & 7 deletions tests/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path"
"runtime"
"strings"
"sync"
)

const TESTS_FOLDER = "tests/integration"
Expand All @@ -24,16 +25,27 @@ func main() {
log.Println(len(testNames), " tests to run")
buildFakeTerraformRegistry()
destroyMode := os.Getenv("DESTROY_MODE")

var wg sync.WaitGroup

for _, testName := range testNames {
if destroyMode == "DESTROY_ONLY" {
terraformDestory(testName)
} else {
success, err := runTest(testName, destroyMode != "NO_DESTROY")
if !success {
log.Fatalln("Halting due to test failure:", err)
wg.Add(1)

go func(testName string) {
if destroyMode == "DESTROY_ONLY" {
terraformDestory(testName)
} else {
success, err := runTest(testName, destroyMode != "NO_DESTROY")
if !success {
log.Fatalln("Halting due to test failure:", err)
}
}
}

wg.Done()
}(testName)
}

wg.Wait()
}
func compileProvider() error {
cmd := exec.Command("go", "build")
Expand Down
19 changes: 12 additions & 7 deletions tests/integration/021_teams/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@ resource "env0_team" "team_resource2" {
description = "team 2 description"
}

data "env0_teams" "all_teams" {}
data "env0_teams" "all_teams" {
depends_on = [env0_team.team_resource1, env0_team.team_resource2]
}

data "env0_team" "team_resource1" {
name = data.env0_teams.all_teams.names[index(data.env0_teams.all_teams.names, env0_team.team_resource1.name)]
}

data "env0_team" "teams" {
for_each = toset(data.env0_teams.all_teams.names)
name = each.value
data "env0_team" "team_resource2" {
name = data.env0_teams.all_teams.names[index(data.env0_teams.all_teams.names, env0_team.team_resource2.name)]
}

output "team1_description" {
value = var.second_run ? data.env0_team.teams[env0_team.team_resource1.name].description : ""
value = var.second_run ? data.env0_team.team_resource1.description : ""
}

output "team2_description" {
value = var.second_run ? data.env0_team.teams[env0_team.team_resource2.name].description : ""
}
value = var.second_run ? data.env0_team.team_resource2.description : ""
}
5 changes: 4 additions & 1 deletion tests/integration/022_templates/expected_outputs.json
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{}
{
"template1_description": "template-1",
"template2_description": "template-2"
}
29 changes: 21 additions & 8 deletions tests/integration/022_templates/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ data "env0_template" "github_template" {
}

resource "env0_template" "github_template1" {
name = "Github Test ${random_string.random.result}-1"
description = "Template description - GitHub"
name = "Github Test Templates ${random_string.random.result}-1"
description = "template-1"
type = "terraform"
repository = data.env0_template.github_template.repository
github_installation_id = data.env0_template.github_template.github_installation_id
Expand All @@ -24,8 +24,8 @@ resource "env0_template" "github_template1" {
}

resource "env0_template" "github_template2" {
name = "Github Test ${random_string.random.result}-2"
description = "Template description - GitHub"
name = "Github Test Templates ${random_string.random.result}-2"
description = "template-2"
type = "terraform"
repository = data.env0_template.github_template.repository
github_installation_id = data.env0_template.github_template.github_installation_id
Expand All @@ -36,9 +36,22 @@ resource "env0_template" "github_template2" {
terraform_version = "0.15.1"
}

data "env0_templates" "all_templates" {}
data "env0_templates" "all_templates" {
depends_on = [env0_template.github_template1, env0_template.github_template2]
}

data "env0_template" "github_template1" {
name = data.env0_templates.all_templates.names[index(data.env0_templates.all_templates.names, env0_template.github_template1.name)]
}

data "env0_template" "github_template2" {
name = data.env0_templates.all_templates.names[index(data.env0_templates.all_templates.names, env0_template.github_template2.name)]
}

output "template1_description" {
value = var.second_run ? data.env0_template.github_template1.description : ""
}

data "env0_template" "templates" {
for_each = toset(data.env0_templates.all_templates.names)
name = each.value
output "template2_description" {
value = var.second_run ? data.env0_template.github_template2.description : ""
}

0 comments on commit 33c54a8

Please sign in to comment.