From 75d08adca9c9294fef79fa2d9a26089837a503e8 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sun, 15 Nov 2026 14:08:32 -0800 Subject: [PATCH] ublk: report a handler panic and a hung submission as test failures The buffer-size control recovers a handler panic into a named failure, and the short-submission controls bound submitAndWait with a timer, so a missing buffer check or a lost/unconsumed SQE fails the oracle's own assertion instead of panicking or hanging until the package timeout. Co-Authored-By: Claude Opus 5.5 --- .../core/frontend/ublk/dispatch_test.go | 13 +++++++++++- .../core/frontend/ublk/uring_linux_test.go | 20 +++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/seaweed-block/core/frontend/ublk/dispatch_test.go b/seaweed-block/core/frontend/ublk/dispatch_test.go index 12eda08572..781a7b368e 100644 --- a/seaweed-block/core/frontend/ublk/dispatch_test.go +++ b/seaweed-block/core/frontend/ublk/dispatch_test.go @@ -143,9 +143,20 @@ func TestDispatch_OutOfRangeNeverTouchesTheBackend(t *testing.T) { } } +// handleNoPanic reports a panic in the handler as a test failure. +func handleNoPanic(t *testing.T, h handler, r request, buf []byte) (res int32) { + t.Helper() + defer func() { + if p := recover(); p != nil { + t.Fatalf("handler panicked on %+v with a %d-byte buffer: %v", r, len(buf), p) + } + }() + return h.handle(context.Background(), r, buf) +} + func TestDispatch_BufferShorterThanRequestIsRefused(t *testing.T) { b := &failingBackend{} - if got := newTestHandler(b).handle(context.Background(), request{op: ioOpWrite, nrSectors: 16}, make([]byte, 4096)); got != -int32(syscall.EINVAL) { + if got := handleNoPanic(t, newTestHandler(b), request{op: ioOpWrite, nrSectors: 16}, make([]byte, 4096)); got != -int32(syscall.EINVAL) { t.Fatalf("result %d, want -EINVAL for a request larger than its buffer", got) } if b.writes != 0 { diff --git a/seaweed-block/core/frontend/ublk/uring_linux_test.go b/seaweed-block/core/frontend/ublk/uring_linux_test.go index 49e30a9a1d..923d258856 100644 --- a/seaweed-block/core/frontend/ublk/uring_linux_test.go +++ b/seaweed-block/core/frontend/ublk/uring_linux_test.go @@ -5,6 +5,7 @@ package ublk import ( "errors" "testing" + "time" "unsafe" "golang.org/x/sys/unix" @@ -85,7 +86,7 @@ func TestURing_ShortSubmissionSubmitsTheRest(t *testing.T) { t.Fatal(err) } } - if err := r.submitAndWait(4); err != nil { + if err := submitWithin(t, r, 4, 5*time.Second); err != nil { t.Fatal(err) } if got := r.reap(nil); len(got) != 4 { @@ -97,7 +98,22 @@ func TestURing_ShortSubmissionSubmitsTheRest(t *testing.T) { if err := r.prepare(opNop, -1, 0, nil, 9); err != nil { t.Fatal(err) } - if err := r.submitAndWait(0); err == nil { + if err := submitWithin(t, r, 0, 5*time.Second); err == nil { t.Fatal("a submission the kernel never consumed was reported as submitted") } } + +// submitWithin runs submitAndWait and fails the test if it does not +// return in time (lost SQEs would leave it waiting forever). +func submitWithin(t *testing.T, r *uring, minComplete uint32, d time.Duration) error { + t.Helper() + done := make(chan error, 1) + go func() { done <- r.submitAndWait(minComplete) }() + select { + case err := <-done: + return err + case <-time.After(d): + t.Fatalf("submitAndWait(%d) did not return within %v: SQEs were lost or never consumed", minComplete, d) + return nil + } +}