Skip to content

Commit

Permalink
修复pool.Put开启 race 时被丢弃测试失败的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkeridea committed Oct 14, 2019
1 parent af8987b commit 44748b8
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pool/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,18 +173,19 @@ func TestPool_Put(t *testing.T) {

p.Put(b)

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

p.Put(b)
}

if b.String() != "xx" {
t.Errorf("b1.String():%s != xx", b.String())
if bb.String() != "xx" {
t.Errorf("b1.String():%s != xx", bb.String())
}
}

0 comments on commit 44748b8

Please sign in to comment.