From: Matt Joiner Date: Sun, 20 Jul 2025 02:08:56 +0000 (+1000) Subject: fs test: Get interrupt to work as expected X-Git-Tag: v1.59.0~2^2~99 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=af1737ea47b8356608838a6f52a7e0859a59f772;p=btrtrc.git fs test: Get interrupt to work as expected --- diff --git a/fs/stream-sintel_test.go b/fs/stream-sintel_test.go index e78ec8a3..3dd57a22 100644 --- a/fs/stream-sintel_test.go +++ b/fs/stream-sintel_test.go @@ -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)