Skip to content

Commit

Permalink
support parallelizing citogo (keybase#23819)
Browse files Browse the repository at this point in the history
  • Loading branch information
jzila authored Apr 17, 2020
1 parent 8b6b642 commit 85db2ad
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions go/citogo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"strings"
"time"

"golang.org/x/sync/errgroup"

"github.com/keybase/client/go/citogo/types"
)

Expand All @@ -25,6 +27,7 @@ type opts struct {
DirBasename string
BuildID string
Branch string
Parallel int
Preserve bool
BuildURL string
NoCompile bool
Expand Down Expand Up @@ -61,6 +64,7 @@ func convertBreakingChars(s string) string {
func (r *runner) parseArgs() (err error) {
flag.IntVar(&r.opts.Flakes, "flakes", 3, "number of allowed flakes")
flag.IntVar(&r.opts.Fails, "fails", -1, "number of fails allowed before quitting")
flag.IntVar(&r.opts.Parallel, "parallel", 1, "number of tests to run in parallel")
flag.StringVar(&r.opts.Prefix, "prefix", "", "test set prefix")
flag.StringVar(&r.opts.S3Bucket, "s3bucket", "", "AWS S3 bucket to write failures to")
flag.StringVar(&r.opts.ReportLambdaFunction, "report-lambda-function", "", "lambda function to report results to")
Expand Down Expand Up @@ -267,16 +271,27 @@ func (r *runner) runTestFixError(t string) error {
}

func (r *runner) runTests() error {
var eg errgroup.Group
q := make(chan string, len(r.tests))
for i := 0; i < r.opts.Parallel; i++ {
eg.Go(func() error {
for f := range q {
err := r.runTestFixError(f)
if err != nil {
return err
}
if r.opts.Pause > 0 {
time.Sleep(r.opts.Pause)
}
}
return nil
})
}
for _, f := range r.tests {
err := r.runTestFixError(f)
if err != nil {
return err
}
if r.opts.Pause > 0 {
time.Sleep(r.opts.Pause)
}
q <- f
}
return nil
close(q)
return eg.Wait()
}

func (r *runner) cleanup() {
Expand Down

0 comments on commit 85db2ad

Please sign in to comment.