Skip to content

Commit

Permalink
Merge pull request dragonflyoss#1426 from SataQiu/fix-pool-test-20200713
Browse files Browse the repository at this point in the history
Fix the bug in unit tests about sync.Pool
  • Loading branch information
lowzj authored Jul 14, 2020
2 parents 8c716a1 + 8d9596e commit 12cfd62
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 12cfd62

Please sign in to comment.