mirror of
https://github.com/golang/go
synced 2024-11-23 13:50:06 -07:00
os/signal: run TestNotifyContextNotifications subtests in parallel
If we run out of time on the first subtest, we don't want to start the second one with essentially no time remaining. (Moreover, there is no compelling reason not to run these tests in parallel, since they send signals to separate processes.) For #51054. Change-Id: I0424e08c3a9d2db986568d5a5c004859b52f7c51 Reviewed-on: https://go-review.googlesource.com/c/go/+/398454 Trust: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Henrique Vicente de Oliveira Pinto <henriquevicente@gmail.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
7c45dafdb2
commit
b4cabaf8c0
@ -713,7 +713,7 @@ func TestNotifyContextNotifications(t *testing.T) {
|
||||
}
|
||||
wg.Wait()
|
||||
<-ctx.Done()
|
||||
fmt.Print("received SIGINT")
|
||||
fmt.Println("received SIGINT")
|
||||
// Sleep to give time to simultaneous signals to reach the process.
|
||||
// These signals must be ignored given stop() is not called on this code.
|
||||
// We want to guarantee a SIGINT doesn't cause a premature termination of the program.
|
||||
@ -730,11 +730,17 @@ func TestNotifyContextNotifications(t *testing.T) {
|
||||
{"multiple", 10},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var subTimeout time.Duration
|
||||
if deadline, ok := t.Deadline(); ok {
|
||||
subTimeout := time.Until(deadline)
|
||||
subTimeout -= subTimeout / 10 // Leave 10% headroom for cleaning up subprocess.
|
||||
timeout := time.Until(deadline)
|
||||
if timeout < 2*settleTime {
|
||||
t.Fatalf("starting test with less than %v remaining", 2*settleTime)
|
||||
}
|
||||
subTimeout = timeout - (timeout / 10) // Leave 10% headroom for cleaning up subprocess.
|
||||
}
|
||||
|
||||
args := []string{
|
||||
@ -750,7 +756,7 @@ func TestNotifyContextNotifications(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("ran test with -check_notify_ctx_notification and it failed with %v.\nOutput:\n%s", err, out)
|
||||
}
|
||||
if want := []byte("received SIGINT"); !bytes.Contains(out, want) {
|
||||
if want := []byte("received SIGINT\n"); !bytes.Contains(out, want) {
|
||||
t.Errorf("got %q, wanted %q", out, want)
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user