mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
test: print each retryable completion and retry decision
This commit is contained in:
1 parent
5ac568bc79
commit
935b7c46cb
3 files changed
+30
-2
No files matched your search
@@ -4,10 +4,11 @@ package main_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/nvme"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/frontend/nvme"
|
||||
)
|
||||
|
||||
func TestInitiatorFlushRetriesTransientCompletion(t *testing.T) {
|
||||
|
||||
@@ -30,6 +30,10 @@ func (e *nvmeStatusError) retryable() bool { return e.status&0x8000 == 0 }
|
||||
// Retry set, or any other error (transport, lost or unexpected bytes), is
|
||||
// returned at once.
|
||||
func retryLikeHost(max int, op func() error) (refused int, err error) {
|
||||
return retryLikeHostReporting(max, op, nil)
|
||||
}
|
||||
|
||||
func retryLikeHostReporting(max int, op func() error, report func(int, uint16)) (refused int, err error) {
|
||||
started := time.Now()
|
||||
for {
|
||||
err = op()
|
||||
@@ -38,6 +42,9 @@ func retryLikeHost(max int, op func() error) (refused int, err error) {
|
||||
return refused, err
|
||||
}
|
||||
refused++
|
||||
if report != nil {
|
||||
report(refused, se.status)
|
||||
}
|
||||
if refused > max {
|
||||
return refused, fmt.Errorf("%w: refused %d times, %d retries used up, elapsed=%s", err, refused, max, time.Since(started))
|
||||
}
|
||||
@@ -95,3 +102,21 @@ func TestRetryLikeHostReportsExhaustedDuration(t *testing.T) {
|
||||
t.Fatalf("missing exhaustion duration: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRetryLikeHostReportsEveryRetryableStatus(t *testing.T) {
|
||||
var statuses []uint16
|
||||
_, err := retryLikeHostReporting(5, func() error { return &nvmeStatusError{op: "Write", status: 0x0104} }, func(attempt int, status uint16) {
|
||||
if attempt != len(statuses)+1 {
|
||||
t.Fatalf("attempt %d", attempt)
|
||||
}
|
||||
statuses = append(statuses, status)
|
||||
})
|
||||
if err == nil || len(statuses) != 6 {
|
||||
t.Fatalf("statuses=%v err=%v", statuses, err)
|
||||
}
|
||||
for _, status := range statuses {
|
||||
if status != 0x0104 {
|
||||
t.Fatalf("status 0x%04x", status)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -871,7 +871,9 @@ func (c *nvmeInitiator) ioCmd(op uint8, lba uint64, blocks int) nvme.CapsuleComm
|
||||
func hostCommand(t *testing.T, op func() error) {
|
||||
t.Helper()
|
||||
started := time.Now()
|
||||
refused, err := retryLikeHost(nvmeHostMaxRetries, op)
|
||||
refused, err := retryLikeHostReporting(nvmeHostMaxRetries, op, func(attempt int, status uint16) {
|
||||
t.Logf("NVMe retryable completion attempt=%d status=0x%04x retry=%t elapsed=%s", attempt, status, attempt <= nvmeHostMaxRetries, time.Since(started))
|
||||
})
|
||||
if refused > 0 {
|
||||
t.Logf("NVMe retryable completions=%d elapsed=%s exhausted=%t", refused, time.Since(started), refused > nvmeHostMaxRetries)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user