aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorMeir Fischer <meirfischer@gmail.com>2017-06-04 00:29:40 -0400
committerIan Lance Taylor <iant@golang.org>2017-06-09 04:38:37 +0000
commit11c61eb6afaf72c4919cc7806f1016c8bcdf311a (patch)
treef0200b248d7a17759c9e94ea552df85fdb9ad507 /src/testing
parent760636d55a87fe7348e9e14ef1474df2a58439de (diff)
downloadgo-11c61eb6afaf72c4919cc7806f1016c8bcdf311a.tar.xz
testing: show in-progress tests upon SIGINT
Because of parallel tests, which have stalled executions, the RUN output of a test can be much earlier than its completion output resulting in hard-to-read verbose output. The tests are displayed in the order in which the output shows that they began, to make it easy to line up with the "RUN" output. Similarly, the definitions of when tests begin and complete is determined by when RUN and FAIL/SKIP/PASS are output since the focus of this code is on enhancing readability. Fixes #19397 Change-Id: I4d0ca3fd268b620484e7a190117f79a33b3dc461 Reviewed-on: https://go-review.googlesource.com/44352 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/testing.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go
index 7754d4e61f..dbe9089fb5 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -224,13 +224,16 @@ import (
"internal/race"
"io"
"os"
+ "os/signal"
"runtime"
"runtime/debug"
"runtime/trace"
+ "sort"
"strconv"
"strings"
"sync"
"sync/atomic"
+ "syscall"
"time"
)
@@ -269,6 +272,10 @@ var (
haveExamples bool // are there examples?
cpuList []int
+
+ inProgressMu sync.Mutex // guards this group of fields
+ inProgressRegistry = make(map[string]int)
+ inProgressIdx int
)
// common holds the elements common between T and B and
@@ -778,9 +785,12 @@ func (t *T) Run(name string, f func(t *T)) bool {
root := t.parent
for ; root.parent != nil; root = root.parent {
}
+ inProgressMu.Lock()
root.mu.Lock()
+ t.registerInProgress()
fmt.Fprintf(root.w, "=== RUN %s\n", t.name)
root.mu.Unlock()
+ inProgressMu.Unlock()
}
// Instead of reducing the running count of this test before calling the
// tRunner and increasing it afterwards, we rely on tRunner keeping the
@@ -942,6 +952,11 @@ func (t *T) report() {
}
dstr := fmtDuration(t.duration)
format := "--- %s: %s (%s)\n"
+
+ inProgressMu.Lock()
+ defer inProgressMu.Unlock()
+ defer t.registerComplete()
+
if t.Failed() {
t.flushToParent(format, "FAIL", t.name, dstr)
} else if t.chatty {
@@ -953,6 +968,39 @@ func (t *T) report() {
}
}
+func (t *T) registerInProgress() {
+ if !t.chatty {
+ return
+ }
+ inProgressRegistry[t.name] = inProgressIdx
+ inProgressIdx++
+}
+
+func (t *T) registerComplete() {
+ if !t.chatty {
+ return
+ }
+ delete(inProgressRegistry, t.name)
+}
+
+func reportTestsInProgress() {
+ if len(inProgressRegistry) == 0 {
+ return
+ }
+ idxToName := make(map[int]string)
+ var indexes []int
+ for name, idx := range inProgressRegistry {
+ idxToName[idx] = name
+ indexes = append(indexes, idx)
+ }
+ sort.Ints(indexes)
+ var namesInOrder []string
+ for _, idx := range indexes {
+ namesInOrder = append(namesInOrder, idxToName[idx])
+ }
+ fmt.Printf("\ntests in progress: %s\n", strings.Join(namesInOrder, ", "))
+}
+
func listTests(matchString func(pat, str string) (bool, error), tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample) {
if _, err := matchString(*matchList, "non-empty"); err != nil {
fmt.Fprintf(os.Stderr, "testing: invalid regexp in -test.list (%q): %s\n", *matchList, err)
@@ -1056,6 +1104,24 @@ func (m *M) before() {
fmt.Fprintf(os.Stderr, "testing: cannot use -test.coverprofile because test binary was not built with coverage enabled\n")
os.Exit(2)
}
+ if Verbose() {
+ sigCh := make(chan os.Signal, 1)
+ signal.Notify(sigCh, os.Interrupt)
+ go func() {
+ <-sigCh
+ signal.Stop(sigCh)
+ inProgressMu.Lock()
+ reportTestsInProgress()
+ inProgressMu.Unlock()
+ proc, err := os.FindProcess(syscall.Getpid())
+ if err == nil {
+ err = proc.Signal(os.Interrupt)
+ }
+ if err != nil {
+ os.Exit(2)
+ }
+ }()
+ }
}
// after runs after all testing.