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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
馃悰 Fix RemoveOwnerRef unit test to use fresh ownerRefs for each test case #7309
馃悰 Fix RemoveOwnerRef unit test to use fresh ownerRefs for each test case #7309
Conversation
I think this needs to be fixed in 1.2 /cherrypick release-1.2 |
@dlipovetsky: once the present PR merges, I will cherry-pick it on top of release-1.2 in a new PR and assign it to you. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
If I think the issue is not at all clear, so here's a simplified example that demonstrates how We need to make it clear to callers that they must not use the input slice after calling Personally, I find it very easy to misuse this function in its current implementation , and I would prefer that it does not mutate its input, at the expense of allocating memory for a copy. The bug in #7310 was possible precisely because |
I also recognize that the complementary functions from this package ( |
Agree these functions would be better designed if they did not mutate their input, but as they're public and exported I'm not sure if we can change the behaviour directly, we'd have to deprecate and replace (which should be fine.). Why do you think the functions are designed to work like this? |
You're right.
That's a good question. I suspect it's because the functions use I see two alternative designs: (a) make a copy of the source array, or (b) require the caller to pass the source array by reference. Here's a go playground example of both. |
Since the unit test has the same bug as the one in #7310, I will update this PR to fix the unit test only. I will open a separate PR with an alternate implementation of these functions. |
It might be best to wait to see if we can get consensus on:
IMO the answers are yes, yes, and |
This reverts commit da5da78bf6f972e7cc2dc1f10f750a8df65df8a9.
Since RemoveOwnerRef may modify the underlying array, the same ownerRefs should not be used for different test cases.
I've updated this PR to just fix the unit test.
Agreed. I'll wait for others to chime in here, but I can also start GitHub Discussion. |
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.
/approve
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: vincepri The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@dlipovetsky: new pull request created: #7313 In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@dlipovetsky Seeing as this is merged do you mind opening an issue to capture the broader problem with this set of funcitons? |
What this PR does / why we need it:
Fixes the
RemoveOwnerRef
unit test so that one test case does not mutate the ownerRefs test fixture used in another test case.The
RemoveOwnerRef
function mutates its input.As far as I understand, it is designed to not mutate its input.This seems to be by design. I explain why I think this is poor design; namely, that it is easy to misuse, and allows subtle bugs like #7310.The reason that it mutates its input is that it calls
append
, which re-uses the underlying array. This behavior came as a surprise to me, although it is noted in the "fine print":NOTE: The unit tests will fail until a related bug fix, #7310 is merged.Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #