-
Notifications
You must be signed in to change notification settings - Fork 773
Fix the bug in unit tests about sync.Pool #1426
Conversation
It's caused by the race detecting of |
Signed-off-by: SataQiu <[email protected]>
950092e
to
8d9596e
Compare
@@ -1,3 +1,6 @@ | |||
// BufferPool is no-op under race detector, so all these tests do not work. | |||
// +build !race | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
:)
Lines 25 to 28 in 12cfd62
for d in $(eval "${cmd}") | |
do | |
go test -race -coverprofile=profile.out -covermode=atomic "${d}" | |
if [ "$?" != "0" ]; then |
// 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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I will merge this to make the CI pass.
If there is a better solution, please submit another pull request.
Fix the bug in unit tests about sync.Pool
Ⅰ. Describe what this PR did
Callers should not assume any relation between values passed to
Put
and the values returned byGet
.Ref: https://github.com/golang/go/blob/master/src/sync/pool.go#L116-L151
Ref: https://github.com/golang/go/blob/master/src/sync/pool_test.go#L28-L42
It seems that we should pin the P when do the unit test :)
Ⅱ. Does this pull request fix one issue?
Fixes: #1416
Ⅲ. Why don't you add test cases (unit test/integration test)? (你真的觉得不需要加测试吗?)
Ⅳ. Describe how to verify it
Ⅴ. Special notes for reviews