t.Parallel()
method GO-W6007 9 "github.com/stretchr/testify/require"
10)
11
12func TestRegistration_GardenServerFails(t *testing.T) {13 t.Parallel()
14
15 dc := dctest.Init(t, "../docker-compose.yml", "overrides/broken_containerd_socket.yml")
7 "github.com/concourse/concourse/integration/internal/flytest"
8)
9
10func TestTags_EmptyString(t *testing.T) {11 t.Parallel()
12
13 dc := dctest.Init(t, "../docker-compose.yml", "overrides/empty_tag.yml")
10 "github.com/stretchr/testify/require"
11)
12
13func TestStreamed_ResourceCache(t *testing.T) {14 t.Parallel()
15
16 dockerComposeDoc := ypath.Load(t, "../docker-compose.yml")
13 "github.com/stretchr/testify/require"
14)
15
16func TestRestart_AttachToRunningBuild(t *testing.T) {17 t.Parallel()
18
19 dc := dctest.Init(t, "../docker-compose.yml", "overrides/restartable.yml")
22 require.Contains(t, output, "1480")
23}
24
25func TestMTU_Manual(t *testing.T) {26 t.Parallel()
27
28 dc := dctest.Init(t, "../docker-compose.yml", "overrides/custom_mtu.yml")
Using the t.Parallel() method can be tricky and ollowing are some common inappropriate
usages of t.Parallel
:
— t.Parallel()
is called in either a top-level test function or a sub-test function only
— t.Parallel()
is called in the sub-test function; it is post-processed by defer
instead of t.Cleanup()
Here's a good blog post explaining how t.Parallel
should be used.
The description of the Parallel()
method from Go's official documentation:
func (t *T) Parallel()
Parallel signals that this test is to be run in parallel with (and only
with) other parallel tests. When a test is run multiple times due to use of
-test.count or -test.cpu, multiple instances of a single test never run in
parallel with each other.
func Test_TB2(t *testing.T) {
teardown := setup("Test_TB2")
t.Cleanup(teardown)
t.Parallel() // "Test_TB2's subtests should call t.Parallel"
tests := []struct { name string }{
{ name: "TB2_Sub1" },
{ name: "TB2_Sub2" },
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
call(tt.name)
})
}
}
func Test_Func1(t *testing.T) {
teardown := setup("Test_Func1")
t.Cleanup(teardown)
// "Test_Func1 should call t.Parallel on the top level as well"
t.Run("Func1_Sub1", func(t *testing.T) {
call("Func1_Sub1")
t.Parallel()
})
t.Run("Func1_Sub2", func(t *testing.T) {
call("Func1_Sub2")
t.Parallel()
})
}
func Test_TB2(t *testing.T) {
teardown := setup("Test_TB2")
t.Cleanup(teardown)
t.Parallel()
tests := []struct { name string }{
{ name: "TB2_Sub1" },
{ name: "TB2_Sub2" },
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
call(tt.name)
})
}
}
func Test_Func1(t *testing.T) {
teardown := setup("Test_Func1")
t.Cleanup(teardown)
t.Parallel()
t.Run("Func1_Sub1", func(t *testing.T) {
call("Func1_Sub1")
t.Parallel()
})
t.Run("Func1_Sub2", func(t *testing.T) {
call("Func1_Sub2")
t.Parallel()
})
}