Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Fix the bug in unit tests about sync.Pool #1426

Merged
merged 1 commit into from
Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a workaround solution, but it will not run unit-testing of this file in current CI flow.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can do something in hack/unit-test.sh, such as adding -race dynamically for go test :)
https://github.com/dragonflyoss/Dragonfly/blob/12cfd62bfc56554a650c506bc5d51a44fcd115ad/hack/unit-test.sh#L25-L28

/*
* 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)

Comment on lines +58 to +62
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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