Skip to content

Commit 2c7f60d

Browse files
author
Tom Manville
committed
Run multiple suite instances in parallel
1 parent 20d25e2 commit 2c7f60d

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

run.go

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ var (
3434
oldListFlag = flag.Bool("gocheck.list", false, "List the names of all tests that will be run")
3535
oldWorkFlag = flag.Bool("gocheck.work", false, "Display and do not remove the test working directory")
3636

37-
newFilterFlag = flag.String("check.f", "", "Regular expression selecting which tests and/or suites to run")
38-
newVerboseFlag = flag.Bool("check.v", false, "Verbose mode")
39-
newStreamFlag = flag.Bool("check.vv", false, "Super verbose mode (disables output caching)")
40-
newBenchFlag = flag.Bool("check.b", false, "Run benchmarks")
41-
newBenchTime = flag.Duration("check.btime", 1*time.Second, "approximate run time for each benchmark")
42-
newBenchMem = flag.Bool("check.bmem", false, "Report memory benchmarks")
43-
newListFlag = flag.Bool("check.list", false, "List the names of all tests that will be run")
44-
newWorkFlag = flag.Bool("check.work", false, "Display and do not remove the test working directory")
37+
newFilterFlag = flag.String("check.f", "", "Regular expression selecting which tests and/or suites to run")
38+
newVerboseFlag = flag.Bool("check.v", false, "Verbose mode")
39+
newStreamFlag = flag.Bool("check.vv", false, "Super verbose mode (disables output caching)")
40+
newBenchFlag = flag.Bool("check.b", false, "Run benchmarks")
41+
newBenchTime = flag.Duration("check.btime", 1*time.Second, "approximate run time for each benchmark")
42+
newBenchMem = flag.Bool("check.bmem", false, "Report memory benchmarks")
43+
newListFlag = flag.Bool("check.list", false, "List the names of all tests that will be run")
44+
newWorkFlag = flag.Bool("check.work", false, "Display and do not remove the test working directory")
45+
suiteParallelismFlag = flag.Int("check.suitep", 1, "Run different test suites in parallel")
4546
)
4647

4748
// TestingT runs all test suites registered with the Suite function,
@@ -55,7 +56,7 @@ func TestingT(testingT *testing.T) {
5556
conf := &RunConf{
5657
Filter: *oldFilterFlag + *newFilterFlag,
5758
Verbose: *oldVerboseFlag || *newVerboseFlag,
58-
Stream: *oldStreamFlag || *newStreamFlag,
59+
Stream: (*oldStreamFlag || *newStreamFlag) && (*suiteParallelismFlag <= 1),
5960
Benchmark: *oldBenchFlag || *newBenchFlag,
6061
BenchmarkTime: benchTime,
6162
BenchmarkMem: *newBenchMem,
@@ -80,8 +81,28 @@ func TestingT(testingT *testing.T) {
8081
// provided run configuration.
8182
func RunAll(runConf *RunConf) *Result {
8283
result := Result{}
83-
for _, suite := range allSuites {
84-
result.Add(Run(suite, runConf))
84+
queueCh := make(chan interface{})
85+
go func() {
86+
for _, s := range allSuites {
87+
queueCh <- s
88+
}
89+
close(queueCh)
90+
}()
91+
92+
p := *suiteParallelismFlag
93+
if p <= 0 {
94+
p = 1
95+
}
96+
resCh := make(chan *Result)
97+
for i := 0; i < p; i++ {
98+
go func() {
99+
for s := range queueCh {
100+
resCh <- Run(s, runConf)
101+
}
102+
}()
103+
}
104+
for _ = range make([]struct{}, len(allSuites)) {
105+
result.Add(<-resCh)
85106
}
86107
return &result
87108
}

0 commit comments

Comments
 (0)