From fa95b67c92ccf880a76c228a38139ed2fdb8acb6 Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Thu, 30 Jul 2015 10:29:05 +0000 Subject: [PATCH] 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 --- test/run_all.sh | 2 +- testing/runner/runner.go | 44 +++++++++++++++++++++++++++------------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/test/run_all.sh b/test/run_all.sh index 54eebf8c..bf83c86c 100755 --- a/test/run_all.sh +++ b/test/run_all.sh @@ -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 diff --git a/testing/runner/runner.go b/testing/runner/runner.go index c468bb04..5ee67f61 100644 --- a/testing/runner/runner.go +++ b/testing/runner/runner.go @@ -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") @@ -45,6 +45,7 @@ type schedule struct { } type result struct { + test errored bool hosts []string } @@ -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 } @@ -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++ } @@ -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() {