Diff only after checking repeatability#1694
Closed
rokatyy wants to merge 1 commit intostretchr:masterfrom
Closed
Conversation
Collaborator
|
It's not working because we've lost the case where there are matching calls but all of them have run out of times they should be called, findExpectedCall returns -1 and the last matcing one. That's not really the job of "findExpectedCall", this part of the Mock class needs careful re-factoring and could include the cleanup intended by this PR. findClosestCall and they way Mock.Diff is called could also use work. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Optimisation of
findExpectedCallMotivation
That's quite a long story about how I got here. We are migrating Nuclio from Go version 1.21 to 1.23, and apparently, something has changed there in between. This test stopped working, failing on a mock call. So, I decided to dig into how testify works and noticed that if you have more than one call of the same function in
ExpectedCalls, the Diff function will still run against it, even if the function has already been called once and its Repeatability is-1. And it would be fine if only we didn't havesuite.Require().Equalas part ofmock.MatchedByfunction, which failed on the 1st iteration here without even reaching the required iteration inExpectedCalls.UPD:I noticed that the tests fail in cases where this function returns a call without considering Repeatability. While this behavior is tied to the implementation details, it can take quite a bit of time to figure out the root cause of these failures, which isn't ideal from a UX perspective. This PR is more of a suggestion rather than a change request, so feel free to close it if you believe it’s unnecessary.