-
Notifications
You must be signed in to change notification settings - Fork 529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
util.RequestBuffers: Fix test flakiness #6905
Conversation
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
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.
the failure seems to be here
34: assert.Same(t, b1, b)
why do we need to assert that the returned slice is the same as the previous one? Is this part of the API of *RequestBuffers
?
@dimitarvdimitrov it's just to make sure it uses the pool. |
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.
thanks for fixing it
) | ||
|
||
// Pool is an abstraction of sync.Pool, for testability. | ||
type Pool interface { |
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.
this looks like an existing interface, which made me think this is probably a good fit for that pool package, but that's a different topic
Lines 12 to 18 in 942e16c
// Interface defines the same functions of sync.Pool. | |
type Interface interface { | |
// Put is sync.Pool.Put(). | |
Put(x any) | |
// Get is sync.Pool.Get(). | |
Get() any | |
} |
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.
Aha, thanks @dimitarvdimitrov - I was not aware of this package.
What this PR does
util.TestRequestBuffers
is flaky due tosync.Pool
not being 100% deterministic, see example CI failure.This PR abstracts
sync.Pool
through an interface, which gets faked in tests for deterministic behaviour.Which issue(s) this PR fixes or relates to
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]
.about-versioning.md
updated with experimental features.