Add summary to bottom of test runner output.

Also, don't sort tests by #hosts when run sequentially, and fix typo in run_all.sh.

Fixes #1240
This commit is contained in:
Tom Wilkie committed 2015-07-30 10:29:05 +00:00
1 parent 728203912e
commit fa95b67c92
2 files changed
+31 -15

No files matched your search

+1 -1
View File
@@ -19,7 +19,7 @@ if [ -n "$CIRCLECI" -a -z "$NO_SCHEDULER" ]; then
fi fi
# If running on circle or PARALLEL is not empty, run tests in parallel # 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" RUNNER_ARGS="$RUNNER_ARGS -parallel"
fi fi
+30 -14
View File
@@ -24,7 +24,7 @@ const (
) )
var ( var (
start = ansi.ColorCode("white+ub") start = ansi.ColorCode("black+ub")
fail = ansi.ColorCode("red+b") fail = ansi.ColorCode("red+b")
succ = ansi.ColorCode("green+b") succ = ansi.ColorCode("green+b")
reset = ansi.ColorCode("reset") reset = ansi.ColorCode("reset")
@@ -45,6 +45,7 @@ type schedule struct {
} }
type result struct { type result struct {
test
errored bool errored bool
hosts []string hosts []string
} }
@@ -171,19 +172,28 @@ func getTests(testNames []string) (tests, error) {
tests = append(tests, test{name, numHosts}) tests = append(tests, test{name, numHosts})
fmt.Printf("Test %s needs %d hosts\n", name, numHosts) fmt.Printf("Test %s needs %d hosts\n", name, numHosts)
} }
sort.Sort(sort.Reverse(tests))
return tests, nil 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) resultsChan := make(chan result)
outstanding := 0 outstanding := 0
errored := false failed := tests{}
for len(tests) > 0 || outstanding > 0 { for len(ts) > 0 || outstanding > 0 {
// While we have some free hosts, try and schedule // While we have some free hosts, try and schedule
// a test on them // a test on them
for len(hosts) > 0 { for len(hosts) > 0 {
test, ok := tests.pick(len(hosts)) test, ok := ts.pick(len(hosts))
if !ok { if !ok {
break break
} }
@@ -192,7 +202,7 @@ func parallel(tests tests, hosts []string) bool {
go func() { go func() {
errored := test.run(testHosts) errored := test.run(testHosts)
resultsChan <- result{errored, testHosts} resultsChan <- result{test, errored, testHosts}
}() }()
outstanding++ outstanding++
} }
@@ -202,17 +212,23 @@ func parallel(tests tests, hosts []string) bool {
result := <-resultsChan result := <-resultsChan
hosts = append(hosts, result.hosts...) hosts = append(hosts, result.hosts...)
outstanding-- 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 { func sequential(ts tests, hosts []string) bool {
errored := false failed := tests{}
for _, test := range tests { for _, test := range ts {
errored = test.run(hosts) || errored if test.run(hosts) {
failed = append(failed, test)
}
} }
return errored summary(ts, failed)
return len(failed) > 0
} }
func main() { func main() {