Skip to content

Commit 68a752e

Browse files
committed
Merge remote-tracking branch 'origin/main' into sams/list-genconfig
2 parents 8c12ea0 + f31477f commit 68a752e

27 files changed

+1535
-485
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: ENHANCEMENTS
2+
body: ' TF Test: Allow parallel execution of teardown operations'
3+
time: 2025-05-27T09:57:55.267277+02:00
4+
custom:
5+
Issue: "37169"

internal/backend/local/test.go

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import (
1515
"github.com/hashicorp/terraform/internal/command/junit"
1616
"github.com/hashicorp/terraform/internal/command/views"
1717
"github.com/hashicorp/terraform/internal/configs"
18-
"github.com/hashicorp/terraform/internal/dag"
19-
"github.com/hashicorp/terraform/internal/logging"
2018
"github.com/hashicorp/terraform/internal/moduletest"
2119
"github.com/hashicorp/terraform/internal/moduletest/graph"
2220
"github.com/hashicorp/terraform/internal/terraform"
@@ -61,7 +59,6 @@ type TestSuiteRunner struct {
6159
Verbose bool
6260

6361
Concurrency int
64-
semaphore terraform.Semaphore
6562
}
6663

6764
func (runner *TestSuiteRunner) Stop() {
@@ -82,7 +79,6 @@ func (runner *TestSuiteRunner) Test() (moduletest.Status, tfdiags.Diagnostics) {
8279
if runner.Concurrency < 1 {
8380
runner.Concurrency = 10
8481
}
85-
runner.semaphore = terraform.NewSemaphore(runner.Concurrency)
8682

8783
suite, suiteDiags := runner.collectTests()
8884
diags = diags.Append(suiteDiags)
@@ -124,6 +120,7 @@ func (runner *TestSuiteRunner) Test() (moduletest.Status, tfdiags.Diagnostics) {
124120
Verbose: runner.Verbose,
125121
Render: runner.View,
126122
UnparsedVariables: currentGlobalVariables,
123+
Concurrency: runner.Concurrency,
127124
})
128125

129126
fileRunner := &TestFileRunner{
@@ -254,7 +251,7 @@ func (runner *TestFileRunner) Test(file *moduletest.File) {
254251
}
255252

256253
// walk and execute the graph
257-
diags = diags.Append(runner.walkGraph(g))
254+
diags = diags.Append(graph.Walk(g, runner.EvalContext))
258255

259256
// If the graph walk was terminated, we don't want to add the diagnostics.
260257
// The error the user receives will just be:
@@ -269,52 +266,6 @@ func (runner *TestFileRunner) Test(file *moduletest.File) {
269266
file.Diagnostics = file.Diagnostics.Append(diags)
270267
}
271268

272-
// walkGraph goes through the graph and execute each run it finds.
273-
func (runner *TestFileRunner) walkGraph(g *terraform.Graph) tfdiags.Diagnostics {
274-
sem := runner.Suite.semaphore
275-
276-
// Walk the graph.
277-
walkFn := func(v dag.Vertex) tfdiags.Diagnostics {
278-
if runner.EvalContext.Cancelled() {
279-
// If the graph walk has been cancelled, the node should just return immediately.
280-
// For now, this means a hard stop has been requested, in this case we don't
281-
// even stop to mark future test runs as having been skipped. They'll
282-
// just show up as pending in the printed summary. We will quickly
283-
// just mark the overall file status has having errored to indicate
284-
// it was interrupted.
285-
return nil
286-
}
287-
288-
// the walkFn is called asynchronously, and needs to be recovered
289-
// separately in the case of a panic.
290-
defer logging.PanicHandler()
291-
292-
log.Printf("[TRACE] vertex %q: starting visit (%T)", dag.VertexName(v), v)
293-
294-
defer func() {
295-
if r := recover(); r != nil {
296-
// If the walkFn panics, we get confusing logs about how the
297-
// visit was complete. To stop this, we'll catch the panic log
298-
// that the vertex panicked without finishing and re-panic.
299-
log.Printf("[ERROR] vertex %q panicked", dag.VertexName(v))
300-
panic(r) // re-panic
301-
}
302-
log.Printf("[TRACE] vertex %q: visit complete", dag.VertexName(v))
303-
}()
304-
305-
// Acquire a lock on the semaphore
306-
sem.Acquire()
307-
defer sem.Release()
308-
309-
if executable, ok := v.(graph.GraphNodeExecutable); ok {
310-
executable.Execute(runner.EvalContext)
311-
}
312-
return nil
313-
}
314-
315-
return g.AcyclicGraph.Walk(walkFn)
316-
}
317-
318269
func (runner *TestFileRunner) renderPreWalkDiags(file *moduletest.File) (walkCancelled bool) {
319270
errored := file.Diagnostics.HasErrors()
320271
// Some runs may have errored during the graph build, but we didn't fail immediately

0 commit comments

Comments
 (0)