-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparallel.go
More file actions
53 lines (47 loc) · 1.2 KB
/
parallel.go
File metadata and controls
53 lines (47 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package test
import (
"github.com/blugnu/test/internal/testframe"
"github.com/blugnu/test/test"
)
// IsParallel returns true if the current test is running in parallel or is a
// sub-test of a parallel test.
func IsParallel() bool {
return testframe.IsParallel()
}
// Parallel establishes a new test frame scheduled for parallel execution.
// It is intended to be used as an alternative to With(t) for a test that
// is intended to run entirely in parallel.
//
// i.e. use:
//
// func TestSomething(t *testing.T) {
// Parallel(t)
// // ... test code here ...
// }
//
// instead of:
//
// func TestSomething(t *testing.T) {
// With(t)
//
// Run(ParallelTest("something", func() {
// // ... test code here ...
// }))
// }
//
// Parallel must not be called from a test that is already parallel or with
// a nil argument; in both cases the test will be failed as invalid.
func Parallel(t TestingT) {
// mark t as a helper if possible
if t, ok := testframe.Peek[TestingT](); ok {
t.Helper()
}
switch {
case t == nil:
test.Invalid("Parallel() cannot be called with nil")
case testframe.IsParallel():
test.Invalid("Parallel() must not be called from a parallel test")
}
With(t)
t.Parallel()
}