]> Cypherpunks repositories - gostls13.git/commitdiff
os/signal: run TestNotifyContextNotifications subtests in parallel
authorBryan C. Mills <bcmills@google.com>
Tue, 5 Apr 2022 15:51:43 +0000 (11:51 -0400)
committerBryan Mills <bcmills@google.com>
Tue, 5 Apr 2022 17:35:18 +0000 (17:35 +0000)
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>

src/os/signal/signal_test.go

index 3182e83b4e9f738fe14846ab31404a972d0f0175..086ecdbcd5e73f50d0ed65aaea5bd4bf3a7e73ff 100644 (file)
@@ -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)
                        }
                })