Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform test: Execute eligible test runs in parallel #36300

Merged
merged 38 commits into from
Feb 5, 2025

Conversation

dsa0x
Copy link
Contributor

@dsa0x dsa0x commented Jan 8, 2025

Fixes #34180

This PR introduces a graph-based execution model into the terraform test framework. With this model, test runs are able to execute in parallel. However, the rules for executing 2 runs in parallel must be fulfilled. Both runs must not share the same state, and there must be no interdependency between them.
The PR also introduces a new "test" block to test files. The block can be used to annotate the file's runs as candidates for parallelism. Each individual run block can however also set this attribute.
For now, the execution of a test run is split between the Execute method of the NodeTestRun, and the graph walk callback itself. Eventually, all logic should be moved into the Execute method.

Target Release

1.11.x

CHANGELOG entry

  • This change is user-facing and I added a changelog entry.
  • This change is not user-facing.

@dsa0x dsa0x force-pushed the sams/tf-test-run-parallel branch from 38f192d to 3f8ae6e Compare January 8, 2025 19:21
@dsa0x dsa0x force-pushed the sams/tf-test-run-parallel branch from 3f8ae6e to f2201ea Compare January 16, 2025 12:40
@dsa0x dsa0x force-pushed the sams/tf-test-run-parallel branch from f2201ea to 754bc4e Compare January 16, 2025 12:49
@dsa0x dsa0x force-pushed the sams/tf-test-run-parallel branch 2 times, most recently from d71ee5e to 6871a7d Compare January 16, 2025 15:58
@dsa0x dsa0x force-pushed the sams/tf-test-run-parallel branch from eeeb05b to e94cd79 Compare January 16, 2025 22:18
@dsa0x dsa0x changed the title Build and execute tf test file runs in a graph Terraform test: Execute eligible test runs in parallel Jan 17, 2025
@dsa0x dsa0x force-pushed the sams/tf-test-run-parallel branch from e94cd79 to 554af21 Compare January 17, 2025 11:43
@dsa0x dsa0x force-pushed the sams/tf-test-run-parallel branch from e3dbde7 to 861afba Compare January 17, 2025 11:53
internal/backend/local/test.go Outdated Show resolved Hide resolved
internal/backend/local/test.go Outdated Show resolved Hide resolved
internal/terraformtest/eval_context.go Outdated Show resolved Hide resolved
@dsa0x dsa0x force-pushed the sams/tf-test-run-parallel branch from 36227ed to 9bce19f Compare February 4, 2025 17:27
@dsa0x dsa0x requested a review from liamcervante February 4, 2025 17:33
@dsa0x dsa0x marked this pull request as ready for review February 4, 2025 17:33
@dsa0x dsa0x requested a review from a team as a code owner February 4, 2025 17:33
Copy link
Member

@liamcervante liamcervante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, looks good - just one question about the ordering of execution vs cancellations.

Comment on lines 374 to 391
if runner.Suite.Stopped {
// Then the test was requested to be stopped, so we just mark each
// following test as skipped, print the status, and move on.
run.Status = moduletest.Skip
runner.Suite.View.Run(run, file, moduletest.Complete, 0)
continue
return
}

file.Lock()
if file.Status == moduletest.Error {
// If the overall test file has errored, we don't keep trying to
// execute tests. Instead, we mark all remaining run blocks as
// skipped, print the status, and move on.
run.Status = moduletest.Skip
runner.Suite.View.Run(run, file, moduletest.Complete, 0)
continue
file.Unlock()
return
}
file.Unlock()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we move this above the .Execute() calls above? Just so we check if we should execute before we do any of the work?

Copy link
Contributor Author

@dsa0x dsa0x Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. It was only okay to do this because most of the execution is still done in this file, but that may change in future, so will move 👍
=> 9555a29

@dsa0x dsa0x merged commit 2f0f537 into main Feb 5, 2025
8 checks passed
@dsa0x dsa0x deleted the sams/tf-test-run-parallel branch February 5, 2025 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Terraform Test: add the ability to run tests in parallel
2 participants