Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: fix potential races with t.Parallel and loops ➿ #3493

Merged
merged 1 commit into from
Nov 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/reconciler/pipelinerun/resources/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ func TestApplyParameters(t *testing.T) {
}},
},
}} {
tt := tt // capture range variable
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
run := &v1beta1.PipelineRun{
Expand Down
1 change: 1 addition & 0 deletions test/cancel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestTaskRunPipelineRunCancel(t *testing.T) {
// on failure, to ensure that cancelling the PipelineRun doesn't cause
// the retrying TaskRun to retry.
for _, numRetries := range []int{0, 1} {
numRetries := numRetries // capture range variable
t.Run(fmt.Sprintf("retries=%d", numRetries), func(t *testing.T) {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
Expand Down
1 change: 1 addition & 0 deletions test/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ func TestExamples(t *testing.T) {

t.Parallel()
for _, path := range getExamplePaths(t, baseDir) {
path := path // capture range variable
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thus is needed because exampleTest called later.. does use t.Parallel()

testName := extractTestName(baseDir, path)
waitValidateFunc := waitValidatePipelineRunDone
kind := "pipelinerun"
Expand Down
2 changes: 2 additions & 0 deletions test/git_checkout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func TestGitPipelineRun(t *testing.T) {
repo: "https://github.com/spring-projects/spring-petclinic",
revision: "main",
}} {
tc := tc // capture range variable
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
ctx := context.Background()
Expand Down Expand Up @@ -182,6 +183,7 @@ func TestGitPipelineRunFail(t *testing.T) {
name: "invalid httpsproxy",
httpsproxy: "invalid.https.proxy.example.com",
}} {
tc := tc // capture range variable
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
ctx := context.Background()
Expand Down
4 changes: 2 additions & 2 deletions test/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ func TestPipelineRun(t *testing.T) {
}}

for i, td := range tds {
i := i // capture range variable
td := td // capture range variable
Comment on lines +210 to +211
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I often use i, td := i, td to avoid the compounding pollution

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😊

t.Run(td.name, func(t *testing.T) {
td := td

t.Parallel()
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
Expand Down
1 change: 1 addition & 0 deletions test/v1alpha1/cancel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestTaskRunPipelineRunCancel(t *testing.T) {
// on failure, to ensure that cancelling the PipelineRun doesn't cause
// the retrying TaskRun to retry.
for _, numRetries := range []int{0, 1} {
numRetries := numRetries // capture range variable
t.Run(fmt.Sprintf("retries=%d", numRetries), func(t *testing.T) {
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
Expand Down
2 changes: 2 additions & 0 deletions test/v1alpha1/git_checkout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func TestGitPipelineRun(t *testing.T) {
repo: "https://github.com/spring-projects/spring-petclinic",
revision: "main",
}} {
tc := tc // capture range variable
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
ctx := context.Background()
Expand Down Expand Up @@ -180,6 +181,7 @@ func TestGitPipelineRunFail(t *testing.T) {
name: "invalid httpsproxy",
httpsproxy: "invalid.https.proxy.example.com",
}} {
tc := tc // capture range variable
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
ctx := context.Background()
Expand Down
3 changes: 2 additions & 1 deletion test/v1alpha1/pipelinerun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ func TestPipelineRun(t *testing.T) {
}}

for i, td := range tds {
i := i // capture range variable
td := td // capture range variable
t.Run(td.name, func(t *testing.T) {
td := td
t.Parallel()
ctx := context.Background()
ctx, cancel := context.WithCancel(ctx)
Expand Down