Skip to content

Commit

Permalink
chore: add changed benchmark for Terragrunt. (#1896)
Browse files Browse the repository at this point in the history
  • Loading branch information
i4ki authored Oct 4, 2024
2 parents 4650f3a + c7bae7d commit a4ce673
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions benchmarks/changed/changed_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,56 @@ func BenchmarkChangeDetection(b *testing.B) {
}
}

func BenchmarkChangeDetectionTFAndTG(b *testing.B) {
b.StopTimer()

const nTfStacks = 10
const nTGstacks = 10

s := sandbox.New(b)
layout := []string{
"f:config.hcl:" + Block("locals",
Expr("account", `read_terragrunt_config(find_in_parent_folders("account.hcl"))`),
).String(),
"f:account.hcl:" + Block("locals",
Str("account_name", "prod"),
Str("aws_account_id", "test"),
).String(),
}
for i := 0; i < nTfStacks; i++ {
layout = append(layout, fmt.Sprintf("f:modules/mod-%d/main.tf:%s", i, "# nothing here"))
layout = append(layout, fmt.Sprintf("s:stack-%d", i))
layout = append(layout, fmt.Sprintf("f:stack-%d/main.tf:%s", i, Block("module",
Labels("something"),
Str("source", fmt.Sprintf("../modules/mod-%d", i)),
).String()))
}
for i := 0; i < nTGstacks; i++ {
layout = append(layout, fmt.Sprintf("f:modules/mod-%d/main.tf:%s", i, "# nothing here"))
layout = append(layout, fmt.Sprintf("s:tg-%d", i))
layout = append(layout, fmt.Sprintf("f:tg-%d/terragrunt.hcl:%s", i, Block("terraform",
Str("source", fmt.Sprintf("../modules/mod-%d", i)),
).String()))
}
s.BuildTree(layout)
s.Git().CommitAll("create repo")
s.Git().Push("main")
s.Git().CheckoutNew("modify-some-modules")
test.WriteFile(b, filepath.Join(s.RootDir(), fmt.Sprintf("modules/mod-%d", nTfStacks-1)), "main.tf", "# modified")
s.Git().CommitAll("module modified")

manager := stack.NewGitAwareManager(s.Config(), s.Git().Unwrap())

b.StartTimer()
for i := 0; i < b.N; i++ {
report, err := manager.ListChanged("origin/main")
assert.NoError(b, err)
assert.EqualInts(b, 2, len(report.Stacks))
assert.EqualStrings(b, fmt.Sprintf("/stack-%d", nTfStacks-1), report.Stacks[0].Stack.Dir.String())
assert.EqualStrings(b, fmt.Sprintf("/tg-%d", nTGstacks-1), report.Stacks[1].Stack.Dir.String())
}
}

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}

0 comments on commit a4ce673

Please sign in to comment.