aboutsummaryrefslogtreecommitdiff
path: root/internal/bufpool/buffers_test.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-04 08:26:56 +0800
committerGravatar Runxi Yu2026-03-04 08:59:53 +0800
commitab7501be34032fb9e5c48726a68ae90a917af9eb (patch)
tree20d005647569befea8133e953c3270e8fd2a2a5b /internal/bufpool/buffers_test.go
parent*: gofumpt (diff)
signatureNo signature
*: Lint
Diffstat (limited to 'internal/bufpool/buffers_test.go')
-rw-r--r--internal/bufpool/buffers_test.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/internal/bufpool/buffers_test.go b/internal/bufpool/buffers_test.go
index 70861d33..224fa98c 100644
--- a/internal/bufpool/buffers_test.go
+++ b/internal/bufpool/buffers_test.go
@@ -15,19 +15,23 @@ func TestBorrowBufferResizeAndAppend(t *testing.T) {
b.Append([]byte("alpha"))
b.Append([]byte("beta"))
+
if got := string(b.Bytes()); got != "alphabeta" {
t.Fatalf("unexpected contents: %q", got)
}
b.Resize(3)
+
if got := string(b.Bytes()); got != "alp" {
t.Fatalf("resize shrink mismatch: %q", got)
}
b.Resize(8)
+
if len(b.Bytes()) != 8 {
t.Fatalf("expected len 8 after grow, got %d", len(b.Bytes()))
}
+
if prefix := string(b.Bytes()[:3]); prefix != "alp" {
t.Fatalf("prefix lost after grow: %q", prefix)
}
@@ -39,6 +43,7 @@ func TestBorrowBufferRelease(t *testing.T) {
b := Borrow(DefaultBufferCap / 2)
b.Append([]byte("data"))
b.Release()
+
if b.buf != nil {
t.Fatal("expected buffer cleared after release")
}
@@ -59,9 +64,11 @@ func TestBorrowUsesLargerPools(t *testing.T) {
if b.pool != poolIndex(classIdx) {
t.Fatalf("expected pooled buffer in class %d, got %d", classIdx, b.pool)
}
+
if cap(b.buf) != classCap {
t.Fatalf("expected capacity %d, got %d", classCap, cap(b.buf))
}
+
b.Release()
b2 := Borrow(request)
@@ -70,6 +77,7 @@ func TestBorrowUsesLargerPools(t *testing.T) {
if b2.pool != poolIndex(classIdx) {
t.Fatalf("expected pooled buffer in class %d on reuse, got %d", classIdx, b2.pool)
}
+
if cap(b2.buf) != classCap {
t.Fatalf("expected capacity %d on reuse, got %d", classCap, cap(b2.buf))
}
@@ -82,6 +90,7 @@ func TestGrowingBufferStaysPooled(t *testing.T) {
defer b.Release()
b.Append(make([]byte, DefaultBufferCap*3))
+
if b.pool == unpooled {
t.Fatal("buffer should stay pooled after growth within limit")
}