diff --git a/internal/backend/local/test.go b/internal/backend/local/test.go index 2b868c1bc11a..5e8742368bda 100644 --- a/internal/backend/local/test.go +++ b/internal/backend/local/test.go @@ -347,6 +347,17 @@ func (runner *TestFileRunner) walkGraph(g *terraform.Graph) tfdiags.Diagnostics switch v := v.(type) { case *graph.NodeTestRun: + file := v.File() + run := v.Run() + if file.GetStatus() == 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) + return + } + // TODO: The execution of a NodeTestRun is currently split between // its Execute method and the continuation of the walk callback. // Eventually, we should move all the logic related to a test run into @@ -356,8 +367,10 @@ func (runner *TestFileRunner) walkGraph(g *terraform.Graph) tfdiags.Diagnostics if diags.HasErrors() { return diags } - // continue + // continue the execution of the test run. case graph.GraphNodeExecutable: + // The only type of executable node in the graph for now + // is a test run, so this is still a no-op. diags = v.Execute(runner.EvalContext) return diags default: @@ -378,17 +391,6 @@ func (runner *TestFileRunner) walkGraph(g *terraform.Graph) tfdiags.Diagnostics runner.Suite.View.Run(run, file, moduletest.Complete, 0) 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) - file.Unlock() - return - } - file.Unlock() key := run.GetStateKey() if run.Config.ConfigUnderTest != nil { diff --git a/internal/moduletest/file.go b/internal/moduletest/file.go index 4896163186ac..761839e7c91b 100644 --- a/internal/moduletest/file.go +++ b/internal/moduletest/file.go @@ -37,3 +37,9 @@ func (f *File) UpdateStatus(status Status) { defer f.Unlock() f.Status = f.Status.Merge(status) } + +func (f *File) GetStatus() Status { + f.Lock() + defer f.Unlock() + return f.Status +} diff --git a/internal/moduletest/graph/node_test_run.go b/internal/moduletest/graph/node_test_run.go index 2bad574098a3..fbc72cffe1ab 100644 --- a/internal/moduletest/graph/node_test_run.go +++ b/internal/moduletest/graph/node_test_run.go @@ -10,6 +10,8 @@ import ( "github.com/hashicorp/terraform/internal/tfdiags" ) +var _ GraphNodeExecutable = (*NodeTestRun)(nil) + type NodeTestRun struct { file *moduletest.File run *moduletest.Run