From: Bryan C. Mills Date: Tue, 5 Apr 2022 15:51:43 +0000 (-0400) Subject: os/signal: run TestNotifyContextNotifications subtests in parallel X-Git-Tag: go1.19beta1~755 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b4cabaf8c094da8387ac6274706fe4850d77ebc6;p=gostls13.git 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 Run-TryBot: Bryan Mills Reviewed-by: Ian Lance Taylor Reviewed-by: Henrique Vicente de Oliveira Pinto TryBot-Result: Gopher Robot --- diff --git a/src/os/signal/signal_test.go b/src/os/signal/signal_test.go index 3182e83b4e..086ecdbcd5 100644 --- a/src/os/signal/signal_test.go +++ b/src/os/signal/signal_test.go @@ -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) } })