Skip to content

Commit 44748b8

Browse files
committed
修复pool.Put开启 race 时被丢弃测试失败的问题
1 parent af8987b commit 44748b8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

pool/buffer_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,19 @@ func TestPool_Put(t *testing.T) {
173173

174174
p.Put(b)
175175

176+
var bb *bytes.Buffer
176177
// 开启 race 时有一定概率导致 Put 被丢弃
177178
pp := (*sync.Pool)(p)
178179
for i := 0; i < 10; i++ {
179-
b = pp.Get().(*bytes.Buffer)
180-
if b.String() == "xx" {
180+
bb = pp.Get().(*bytes.Buffer)
181+
if bb.String() == "xx" {
181182
break
182183
}
183184

184185
p.Put(b)
185186
}
186187

187-
if b.String() != "xx" {
188-
t.Errorf("b1.String():%s != xx", b.String())
188+
if bb.String() != "xx" {
189+
t.Errorf("b1.String():%s != xx", bb.String())
189190
}
190191
}

0 commit comments

Comments
 (0)