]> Sergey Matveev's repositories - btrtrc.git/commitdiff
fs test: Get interrupt to work as expected
authorMatt Joiner <anacrolix@gmail.com>
Sun, 20 Jul 2025 02:08:56 +0000 (12:08 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Sun, 20 Jul 2025 02:10:09 +0000 (12:10 +1000)
fs/stream-sintel_test.go

index e78ec8a347b96d4ab0593f4992237fa8df729df5..3dd57a22f9407d85bd88702ac2be5573b71c4508 100644 (file)
@@ -9,6 +9,7 @@ import (
        "io"
        "io/fs"
        "os"
+       "os/signal"
        "path/filepath"
        "testing"
        "time"
@@ -44,6 +45,9 @@ func copyFile(src, dst string) (err error) {
 }
 
 func TestStreamSintelMagnet(t *testing.T) {
+       ctx := t.Context()
+       ctx, cancel := signal.NotifyContext(ctx, os.Interrupt)
+       defer cancel()
        fileHashes := map[string]string{
                "poster.jpg": "f9223791908131c505d7bdafa7a8aaf5",
                "Sintel.mp4": "083e808d56aa7b146f513b3458658292",
@@ -124,11 +128,13 @@ func TestStreamSintelMagnet(t *testing.T) {
        }
        h := md5.New()
        go func() {
-               <-t.Context().Done()
-               t.Log("testing context done")
+               <-ctx.Done()
                f.Close()
        }()
        _, err = f.WriteTo(io.MultiWriter(h, &w))
+       if ctx.Err() != nil {
+               t.Fatal(ctx.Err())
+       }
        panicif.Err(err)
        err = f.Close()
        panicif.Err(err)