这是indexloc提供的服务,不要输入任何密码
Skip to content

Tests generated with -parallel should use t.Parallel() at the top level of a Test function as well as in the subtest functions #188

@edgio-mwodrich

Description

@edgio-mwodrich

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)
		})
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions