Commit 5bcfd884 authored by Ian Lance Taylor's avatar Ian Lance Taylor

testing: roll back CL 44352 (show in-progress tests upon SIGINT)

CL 44352 changed the behavior of SIGINT, which can break tests that
themselves use SIGINT.  I think we can only implement this if the
testing package has a way to know whether the code under test is using
SIGINT, but os/signal does not provide an API for that.  Roll back for
1.9 and think about this again for 1.10.

Updates #19397

Change-Id: I021c314db2b9d0a80d0088b120a6ade685459990
Reviewed-on: https://go-review.googlesource.com/48370
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 7e172509
...@@ -2633,17 +2633,6 @@ func TestGoTestFlagsAfterPackage(t *testing.T) { ...@@ -2633,17 +2633,6 @@ func TestGoTestFlagsAfterPackage(t *testing.T) {
tg.run("test", "-v", "testdata/flag_test.go", "-args", "-v=7") // Two distinct -v flags. tg.run("test", "-v", "testdata/flag_test.go", "-args", "-v=7") // Two distinct -v flags.
} }
func TestGoTestShowInProgressOnInterrupt(t *testing.T) {
if runtime.GOOS == "windows" || runtime.GOOS == "plan9" {
t.Skipf("skipping test on %s - lack of full unix-like signal support", runtime.GOOS)
}
tg := testgo(t)
defer tg.cleanup()
tg.run("test", "-v", "testdata/inprogress_interrupt_test.go")
testsInProgress := "tests in progress: TestParallel, TestSerial"
tg.grepStdout(testsInProgress, "tests which haven't completed should be listed in progress")
}
func TestGoTestXtestonlyWorks(t *testing.T) { func TestGoTestXtestonlyWorks(t *testing.T) {
tg := testgo(t) tg := testgo(t)
defer tg.cleanup() defer tg.cleanup()
......
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package inprogress_interrupt_test
import (
"os"
"os/signal"
"sync"
"syscall"
"testing"
)
func TestParallel(t *testing.T) {
t.Parallel()
}
func TestSerial(t *testing.T) {
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt)
var wg sync.WaitGroup
wg.Add(1)
go func() {
<-sigCh // catch initial signal
<-sigCh // catch propagated signal
wg.Done()
}()
proc, err := os.FindProcess(syscall.Getpid())
if err != nil {
t.Fatalf("unable to find current process: %v", err)
}
err = proc.Signal(os.Interrupt)
if err != nil {
t.Fatalf("failed to interrupt current process: %v", err)
}
wg.Wait()
}
...@@ -183,7 +183,7 @@ var pkgDeps = map[string][]string{ ...@@ -183,7 +183,7 @@ var pkgDeps = map[string][]string{
"runtime/trace": {"L0"}, "runtime/trace": {"L0"},
"text/tabwriter": {"L2"}, "text/tabwriter": {"L2"},
"testing": {"L2", "flag", "fmt", "internal/race", "os", "os/signal", "runtime/debug", "runtime/pprof", "runtime/trace", "syscall", "time"}, "testing": {"L2", "flag", "fmt", "internal/race", "os", "runtime/debug", "runtime/pprof", "runtime/trace", "time"},
"testing/iotest": {"L2", "log"}, "testing/iotest": {"L2", "log"},
"testing/quick": {"L2", "flag", "fmt", "reflect", "time"}, "testing/quick": {"L2", "flag", "fmt", "reflect", "time"},
"internal/testenv": {"L2", "OS", "flag", "testing", "syscall"}, "internal/testenv": {"L2", "OS", "flag", "testing", "syscall"},
......
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package signal_test package signal
import ( import (
"os" "os"
. "os/signal"
"runtime" "runtime"
"syscall" "syscall"
"testing" "testing"
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
// +build darwin dragonfly freebsd linux netbsd openbsd solaris // +build darwin dragonfly freebsd linux netbsd openbsd solaris
package signal_test package signal
import ( import (
"bytes" "bytes"
...@@ -14,7 +14,6 @@ import ( ...@@ -14,7 +14,6 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec" "os/exec"
. "os/signal"
"runtime" "runtime"
"strconv" "strconv"
"sync" "sync"
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package signal_test package signal
import ( import (
"bytes" "bytes"
......
...@@ -224,16 +224,13 @@ import ( ...@@ -224,16 +224,13 @@ import (
"internal/race" "internal/race"
"io" "io"
"os" "os"
"os/signal"
"runtime" "runtime"
"runtime/debug" "runtime/debug"
"runtime/trace" "runtime/trace"
"sort"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
"syscall"
"time" "time"
) )
...@@ -272,10 +269,6 @@ var ( ...@@ -272,10 +269,6 @@ var (
haveExamples bool // are there examples? haveExamples bool // are there examples?
cpuList []int 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 // common holds the elements common between T and B and
...@@ -785,12 +778,9 @@ func (t *T) Run(name string, f func(t *T)) bool { ...@@ -785,12 +778,9 @@ func (t *T) Run(name string, f func(t *T)) bool {
root := t.parent root := t.parent
for ; root.parent != nil; root = root.parent { for ; root.parent != nil; root = root.parent {
} }
inProgressMu.Lock()
root.mu.Lock() root.mu.Lock()
t.registerInProgress()
fmt.Fprintf(root.w, "=== RUN %s\n", t.name) fmt.Fprintf(root.w, "=== RUN %s\n", t.name)
root.mu.Unlock() root.mu.Unlock()
inProgressMu.Unlock()
} }
// Instead of reducing the running count of this test before calling the // Instead of reducing the running count of this test before calling the
// tRunner and increasing it afterwards, we rely on tRunner keeping the // tRunner and increasing it afterwards, we rely on tRunner keeping the
...@@ -952,11 +942,6 @@ func (t *T) report() { ...@@ -952,11 +942,6 @@ func (t *T) report() {
} }
dstr := fmtDuration(t.duration) dstr := fmtDuration(t.duration)
format := "--- %s: %s (%s)\n" format := "--- %s: %s (%s)\n"
inProgressMu.Lock()
defer inProgressMu.Unlock()
defer t.registerComplete()
if t.Failed() { if t.Failed() {
t.flushToParent(format, "FAIL", t.name, dstr) t.flushToParent(format, "FAIL", t.name, dstr)
} else if t.chatty { } else if t.chatty {
...@@ -968,39 +953,6 @@ func (t *T) report() { ...@@ -968,39 +953,6 @@ 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) { func listTests(matchString func(pat, str string) (bool, error), tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample) {
if _, err := matchString(*matchList, "non-empty"); err != nil { if _, err := matchString(*matchList, "non-empty"); err != nil {
fmt.Fprintf(os.Stderr, "testing: invalid regexp in -test.list (%q): %s\n", *matchList, err) fmt.Fprintf(os.Stderr, "testing: invalid regexp in -test.list (%q): %s\n", *matchList, err)
...@@ -1104,24 +1056,6 @@ func (m *M) before() { ...@@ -1104,24 +1056,6 @@ func (m *M) before() {
fmt.Fprintf(os.Stderr, "testing: cannot use -test.coverprofile because test binary was not built with coverage enabled\n") fmt.Fprintf(os.Stderr, "testing: cannot use -test.coverprofile because test binary was not built with coverage enabled\n")
os.Exit(2) 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. // after runs after all testing.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment