@@ -10,7 +10,6 @@ import (
1010 "github.com/gruntwork-io/terragrunt/internal/discovery"
1111 "github.com/gruntwork-io/terragrunt/internal/filter"
1212 "github.com/gruntwork-io/terragrunt/pkg/options"
13- "github.com/gruntwork-io/terragrunt/test/helpers"
1413 "github.com/gruntwork-io/terragrunt/test/helpers/logger"
1514 "github.com/stretchr/testify/require"
1615)
@@ -20,20 +19,21 @@ import (
2019// guard against: the graph phase reaches a shared unit from several goroutines
2120// at once, so one goroutine's parse stores the config while others read it.
2221//
23- // The shared unit gets a large config and many dependents, repeated across
24- // several Discover calls, so the read/write overlap is reliably observable;
25- // the config size and iteration count carry a margin over the smallest values
26- // that still detect the race on every run. All fixture files live on an
27- // in-memory filesystem, so only parsing costs wall time.
22+ // The shared unit gets a large config and many dependents, so the read/write
23+ // overlap is reliably observable. The dependent count is the load-bearing knob:
24+ // at six dependents the overlap stops being observable at all, so the fixture
25+ // carries double the smallest count that detects the race on every run. The
26+ // whole repo lives on an in-memory filesystem, so only parsing costs wall time
27+ // and a single Discover call suffices.
2828//
2929// To confirm the locks are load-bearing, drop the lock/unlock calls from Unit's
3030// Config, StoreConfig, Reading, and SetReading and run with -race.
3131func TestDiscovery_GraphConcurrentConfigAccessWithRacing (t * testing.T ) {
3232 t .Parallel ()
3333
34- tmpDir := helpers . TmpDirWOSymlinks ( t )
34+ repoRoot := string ( filepath . Separator ) + "repo"
3535
36- v := memGitTopLevelVenv (t , tmpDir )
36+ v := memGitTopLevelVenv (t , repoRoot )
3737
3838 // remote_state is partially decoded during discovery, so a large block is
3939 // walked during parse rather than skipped, which lengthens the parse.
@@ -51,13 +51,13 @@ func TestDiscovery_GraphConcurrentConfigAccessWithRacing(t *testing.T) {
5151 sharedConfig .WriteString (" }\n }\n " )
5252
5353 units := map [string ]string {
54- filepath .Join (tmpDir , "vpc" ): sharedConfig .String (),
54+ filepath .Join (repoRoot , "vpc" ): sharedConfig .String (),
5555 }
5656
57- const leaves = 8
57+ const leaves = 16
5858
5959 for i := range leaves {
60- units [filepath .Join (tmpDir , fmt .Sprintf ("app%d" , i ))] = `
60+ units [filepath .Join (repoRoot , fmt .Sprintf ("app%d" , i ))] = `
6161 dependency "vpc" {
6262 config_path = "../vpc"
6363 }
@@ -68,19 +68,17 @@ func TestDiscovery_GraphConcurrentConfigAccessWithRacing(t *testing.T) {
6868
6969 l := logger .CreateLogger ()
7070 opts := & options.TerragruntOptions {
71- WorkingDir : tmpDir ,
72- RootWorkingDir : tmpDir ,
71+ WorkingDir : repoRoot ,
72+ RootWorkingDir : repoRoot ,
7373 }
7474
7575 filters , err := filter .ParseFilterQueries (l , []string {"{./**}..." })
7676 require .NoError (t , err )
7777
78- for range 4 {
79- d := discovery .NewDiscovery (tmpDir ).
80- WithDiscoveryContext (& component.DiscoveryContext {WorkingDir : tmpDir }).
81- WithFilters (filters )
78+ d := discovery .NewDiscovery (repoRoot ).
79+ WithDiscoveryContext (& component.DiscoveryContext {WorkingDir : repoRoot }).
80+ WithFilters (filters )
8281
83- _ , err := d .Discover (t .Context (), l , v , opts )
84- require .NoError (t , err )
85- }
82+ _ , err = d .Discover (t .Context (), l , v , opts )
83+ require .NoError (t , err )
8684}
0 commit comments