Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Add summary to bottom of test runner output.
Browse files Browse the repository at this point in the history
Also, don't sort tests by #hosts when run sequentially, and fix typo in run_all.sh.

Fixes #1240
  • Loading branch information
Tom Wilkie committed Jul 30, 2015
1 parent 7282039 commit fa95b67
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion test/run_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if [ -n "$CIRCLECI" -a -z "$NO_SCHEDULER" ]; then
fi

# If running on circle or PARALLEL is not empty, run tests in parallel
if [ -n "$CIRCLECI" -o -z "$PARALLEL" ]; then
if [ -n "$CIRCLECI" -o -n "$PARALLEL" ]; then
RUNNER_ARGS="$RUNNER_ARGS -parallel"
fi

Expand Down
44 changes: 30 additions & 14 deletions testing/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
)

var (
start = ansi.ColorCode("white+ub")
start = ansi.ColorCode("black+ub")
fail = ansi.ColorCode("red+b")
succ = ansi.ColorCode("green+b")
reset = ansi.ColorCode("reset")
Expand All @@ -45,6 +45,7 @@ type schedule struct {
}

type result struct {
test
errored bool
hosts []string
}
Expand Down Expand Up @@ -171,19 +172,28 @@ func getTests(testNames []string) (tests, error) {
tests = append(tests, test{name, numHosts})
fmt.Printf("Test %s needs %d hosts\n", name, numHosts)
}
sort.Sort(sort.Reverse(tests))
return tests, nil
}

func parallel(tests tests, hosts []string) bool {
func summary(tests, failed tests) {
if len(failed) > 0 {
fmt.Printf("%s>>> Ran %d tests, %d failed%s\n", fail, len(tests), len(failed), reset)
} else {
fmt.Printf("%s>>> Ran %d tests, all succeeded%s\n", succ, len(tests), reset)
}
}

func parallel(ts tests, hosts []string) bool {
testsCopy := ts
sort.Sort(sort.Reverse(ts))
resultsChan := make(chan result)
outstanding := 0
errored := false
for len(tests) > 0 || outstanding > 0 {
failed := tests{}
for len(ts) > 0 || outstanding > 0 {
// While we have some free hosts, try and schedule
// a test on them
for len(hosts) > 0 {
test, ok := tests.pick(len(hosts))
test, ok := ts.pick(len(hosts))
if !ok {
break
}
Expand All @@ -192,7 +202,7 @@ func parallel(tests tests, hosts []string) bool {

go func() {
errored := test.run(testHosts)
resultsChan <- result{errored, testHosts}
resultsChan <- result{test, errored, testHosts}
}()
outstanding++
}
Expand All @@ -202,17 +212,23 @@ func parallel(tests tests, hosts []string) bool {
result := <-resultsChan
hosts = append(hosts, result.hosts...)
outstanding--
errored = result.errored || errored
if result.errored {
failed = append(failed, result.test)
}
}
return errored
summary(testsCopy, failed)
return len(failed) > 0
}

func sequential(tests tests, hosts []string) bool {
errored := false
for _, test := range tests {
errored = test.run(hosts) || errored
func sequential(ts tests, hosts []string) bool {
failed := tests{}
for _, test := range ts {
if test.run(hosts) {
failed = append(failed, test)
}
}
return errored
summary(ts, failed)
return len(failed) > 0
}

func main() {
Expand Down

0 comments on commit fa95b67

Please sign in to comment.