This repository has been archived by the owner on Dec 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 773
Fix the bug in unit tests about sync.Pool #1426
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
* | ||
|
@@ -18,6 +21,7 @@ package pool | |
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/suite" | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
buf1 := AcquireBuffer() | ||
ReleaseBuffer(buf1) | ||
ReleaseBuffer(nil) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Ref: https://github.com/golang/go/blob/master/src/sync/pool_test.go#L5-L6
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 forgo test
:)https://github.com/dragonflyoss/Dragonfly/blob/12cfd62bfc56554a650c506bc5d51a44fcd115ad/hack/unit-test.sh#L25-L28