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 generated with -parallel should use t.Parallel() at the top level of a Test function as well as in the subtest functions #188

Open
edgio-mwodrich opened this issue Mar 6, 2024 · 0 comments

Comments

@edgio-mwodrich
Copy link

Huge thanks for the addition of -parallel in the first place, it's really handy; just wanted to point out a potential improvement for it here.

Tests generated with -parallel currently only use t.Parallel() in subtest functions, so they run afoul of the golangci-lint linter tparallel: https://github.com/moricho/tparallel which looks for certain inappropriate uses of t.Parallel().

Tests should use t.Parallel() both at the beginning of each Test_ function and at the beginning of each subtest function for optimal parallelism.

e.g.:

func Test_Table2(t *testing.T) {
	t.Parallel()

	tests := []struct {
		name string
	}{
		{
			name: "Table2_Sub1",
		},
		{
			name: "Table2_Sub2",
		},
	}

	for _, tt := range tests {
		tt := tt
		t.Run(tt.name, func(t *testing.T) {
			t.Parallel()
			call(tt.name)
		})
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant