Skip to content

Commit

Permalink
fix: use copy of loop variable in parallel test (#23669)
Browse files Browse the repository at this point in the history
This fixes an occurrence of a loop variable being captured in a
parallel test. With the previous code, only the last test case is
actually exercised. To work around this problem, we create a local
copy of the range variable before the parallel test, as suggested in
the Go documentation for the `testing` package:

https://pkg.go.dev/testing#hdr-Subtests_and_Sub_benchmarks

Issue was found automatically using the `loopvarcapture` linter.
  • Loading branch information
renatolabs authored Aug 24, 2022
1 parent 728070e commit ee8ca45
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions sqlite/migrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func TestScriptVersion(t *testing.T) {
}

for _, tt := range tests {
tt := tt // capture range variable
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit ee8ca45

Please sign in to comment.