Skip to content

Commit

Permalink
refacto(venom): delete --parallel flag (#299)
Browse files Browse the repository at this point in the history
this feature can be done with parallel

ls *.yml|parallel -j 2 venom run {}

Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
  • Loading branch information
yesnault authored Nov 17, 2020
1 parent 687d77c commit 4a8dad7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 40 deletions.
3 changes: 0 additions & 3 deletions cli/venom/run/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ var (
outputDir string
strict bool
noCheckVars bool
parallel int
stopOnFailure bool
enableProfiling bool
v *venom.Venom
Expand All @@ -55,7 +54,6 @@ func init() {
Cmd.Flags().BoolVarP(&strict, "strict", "", false, "Exit with an error code if one test fails")
Cmd.Flags().BoolVarP(&stopOnFailure, "stop-on-failure", "", false, "Stop running Test Suite on first Test Case failure")
Cmd.Flags().BoolVarP(&noCheckVars, "no-check-variables", "", false, "Don't check variables before run")
Cmd.Flags().IntVarP(&parallel, "parallel", "", 1, "--parallel=2 : launches 2 Test Suites in parallel")
Cmd.PersistentFlags().StringVarP(&logLevel, "log", "", "warn", "Log Level : debug, info, warn or disable")
Cmd.PersistentFlags().StringVarP(&outputDir, "output-dir", "", "", "Output Directory: create tests results file inside this directory")
Cmd.PersistentFlags().BoolVarP(&enableProfiling, "profiling", "", false, "Enable Mem / CPU Profile with pprof")
Expand Down Expand Up @@ -103,7 +101,6 @@ Notice that variables initialized with -var-from-file argument can be overrided
v.LogLevel = logLevel
v.OutputDir = outputDir
v.OutputFormat = format
v.Parallel = parallel
v.StopOnFailure = stopOnFailure

if v.EnableProfiling {
Expand Down
49 changes: 13 additions & 36 deletions process.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"os"
"path/filepath"
"strings"
"sync"

nested "github.com/antonfisher/nested-logrus-formatter"
"github.com/gosimple/slug"
Expand Down Expand Up @@ -163,48 +162,26 @@ func (v *Venom) Process(ctx context.Context, path []string) (*Tests, error) {
return nil, err
}

chanEnd := make(chan *TestSuite, 1)
parallels := make(chan *TestSuite, v.Parallel) //Run testsuite in parrallel
wg := sync.WaitGroup{}
testsResult := &Tests{}

wg.Add(len(v.testsuites))
chanToRun := make(chan *TestSuite, len(v.testsuites)+1)

go v.computeStats(testsResult, chanEnd, &wg)
go func() {
for ts := range chanToRun {
parallels <- ts
go func(ts *TestSuite) {
v.runTestSuite(ctx, ts)
chanEnd <- ts
<-parallels
}(ts)
}
}()

for i := range v.testsuites {
chanToRun <- &v.testsuites[i]
v.runTestSuite(ctx, &v.testsuites[i])
v.computeStats(testsResult, &v.testsuites[i])
}

wg.Wait()

return testsResult, nil
}

func (v *Venom) computeStats(testsResult *Tests, chanEnd <-chan *TestSuite, wg *sync.WaitGroup) {
for t := range chanEnd {
testsResult.TestSuites = append(testsResult.TestSuites, *t)
if t.Failures > 0 || t.Errors > 0 {
testsResult.TotalKO += (t.Failures + t.Errors)
} else {
testsResult.TotalOK += len(t.TestCases) - (t.Failures + t.Errors)
}
if t.Skipped > 0 {
testsResult.TotalSkipped += t.Skipped
}

testsResult.Total = testsResult.TotalKO + testsResult.TotalOK + testsResult.TotalSkipped
wg.Done()
func (v *Venom) computeStats(testsResult *Tests, ts *TestSuite) {
testsResult.TestSuites = append(testsResult.TestSuites, *ts)
if ts.Failures > 0 || ts.Errors > 0 {
testsResult.TotalKO += (ts.Failures + ts.Errors)
} else {
testsResult.TotalOK += len(ts.TestCases) - (ts.Failures + ts.Errors)
}
if ts.Skipped > 0 {
testsResult.TotalSkipped += ts.Skipped
}

testsResult.Total = testsResult.TotalKO + testsResult.TotalOK + testsResult.TotalSkipped
}
1 change: 0 additions & 1 deletion venom.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ type Venom struct {
testsuites []TestSuite
variables H
IgnoreVariables []string
Parallel int

EnableProfiling bool
OutputFormat string
Expand Down

0 comments on commit 4a8dad7

Please sign in to comment.