Skip to content
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

Merged
merged 1 commit into from
Dec 12, 2023
Merged

Conversation

aknuds1
Copy link
Contributor

@aknuds1 aknuds1 commented Dec 12, 2023

What this PR does

util.TestRequestBuffers is flaky due to sync.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

  • Tests updated.
  • [na] Documentation added.
  • [na] CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX].
  • [na] about-versioning.md updated with experimental features.

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
@aknuds1 aknuds1 requested a review from a team as a code owner December 12, 2023 12:57
@aknuds1 aknuds1 added the chore label Dec 12, 2023
Copy link
Contributor

@dimitarvdimitrov dimitarvdimitrov left a 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?

@aknuds1
Copy link
Contributor Author

aknuds1 commented Dec 12, 2023

@dimitarvdimitrov it's just to make sure it uses the pool.

Copy link
Contributor

@dimitarvdimitrov dimitarvdimitrov left a 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 {
Copy link
Contributor

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

// 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
}

Copy link
Contributor Author

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.

@aknuds1 aknuds1 merged commit 9fa9c6b into main Dec 12, 2023
30 checks passed
@aknuds1 aknuds1 deleted the arve/requestbuffers-fix-tests branch December 12, 2023 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants