Skip to content
This repository has been archived by the owner on Feb 27, 2023. It is now read-only.

Commit

Permalink
fix the bug in unit tests about sync.Pool
Browse files Browse the repository at this point in the history
Signed-off-by: SataQiu <1527062125@qq.com>
  • Loading branch information
SataQiu committed Jul 14, 2020
1 parent 60051a9 commit 8d9596e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/pool/buffer_pool_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// BufferPool is no-op under race detector, so all these tests do not work.
// +build !race

/*
* Copyright The Dragonfly Authors.
*
Expand All @@ -18,6 +21,7 @@ package pool

import (
"fmt"
"runtime"
"testing"

"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -51,6 +55,11 @@ func (s *BufferPoolTestSuite) TestAcquireBuffer() {
}

func (s *BufferPoolTestSuite) TestReleaseBuffer() {
// Limit to 1 processor to make sure that the goroutine doesn't migrate
// to another P between AcquireBuffer and ReleaseBuffer calls.
prev := runtime.GOMAXPROCS(1)
defer runtime.GOMAXPROCS(prev)

buf1 := AcquireBuffer()
ReleaseBuffer(buf1)
ReleaseBuffer(nil)
Expand Down
9 changes: 9 additions & 0 deletions pkg/pool/writer_pool_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// WriterPool is no-op under race detector, so all these tests do not work.
// +build !race

/*
* Copyright The Dragonfly Authors.
*
Expand All @@ -19,13 +22,19 @@ package pool
import (
"bytes"
"io/ioutil"
"runtime"
"sync"
"testing"

"github.com/stretchr/testify/require"
)

func TestWriter(t *testing.T) {
// Limit to 1 processor to make sure that the goroutine doesn't migrate
// to another P between AcquireWriter and ReleaseWriter calls.
prev := runtime.GOMAXPROCS(1)
defer runtime.GOMAXPROCS(prev)

tmp := writerPool
writerPool = &sync.Pool{}

Expand Down

0 comments on commit 8d9596e

Please sign in to comment.