]> Cypherpunks.ru repositories - gostls13.git/commitdiff
[dev.fuzz] testing/internal/testdeps: use signal.NotifyContext
authorJay Conrod <jayconrod@google.com>
Tue, 9 Feb 2021 15:30:02 +0000 (10:30 -0500)
committerJay Conrod <jayconrod@google.com>
Wed, 10 Feb 2021 18:21:02 +0000 (18:21 +0000)
In RunFuzzWorker and CoordinateFuzzing, use signal.NotifyContext
(new in 1.16) to cancel the context in response to SIGINT. This is
shorter and more correct than what we were doing before.

Change-Id: Id7e9a58e9dd992dffb86e4e0f2e3efd117d03c47
Reviewed-on: https://go-review.googlesource.com/c/go/+/290691
Trust: Jay Conrod <jayconrod@google.com>
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Katie Hockman <katie@golang.org>
src/testing/internal/testdeps/deps.go

index 3d431707210607c59bb6a5b069e0b6653fc56717..1333944d5ee113403a63a91ed73d1d8e6063bf67 100644 (file)
@@ -140,14 +140,9 @@ func (TestDeps) CoordinateFuzzing(timeout time.Duration, parallel int, seed []fu
        if timeout > 0 {
                ctx, cancel = context.WithTimeout(ctx, timeout)
        }
-       interruptC := make(chan os.Signal, 1)
-       signal.Notify(interruptC, os.Interrupt)
-       go func() {
-               <-interruptC
-               cancel()
-       }()
-       defer func() { interruptC <- os.Interrupt }()
-
+       ctx, stop := signal.NotifyContext(ctx, os.Interrupt)
+       defer stop()
+       defer cancel()
        err := fuzz.CoordinateFuzzing(ctx, parallel, seed, corpusDir, cacheDir)
        if err == ctx.Err() {
                return nil
@@ -163,14 +158,9 @@ func (TestDeps) RunFuzzWorker(fn func([]byte) error) error {
        // If only the coordinator process is interrupted, it tells each worker
        // process to stop by closing its "fuzz_in" pipe.
        ctx, cancel := context.WithCancel(context.Background())
-       interruptC := make(chan os.Signal, 1)
-       signal.Notify(interruptC, os.Interrupt)
-       go func() {
-               <-interruptC
-               cancel()
-       }()
-       defer func() { interruptC <- os.Interrupt }()
-
+       ctx, stop := signal.NotifyContext(ctx, os.Interrupt)
+       defer stop()
+       defer cancel()
        err := fuzz.RunFuzzWorker(ctx, fn)
        if err == ctx.Err() {
                return nil