mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
8640169e5c
commit
75d08adca9
2 files changed
+30
-3
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user