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

Address races when using Returns and ReturnsOnCall, and make the behavior of ReturnsOnCall be less annoying. #84

Closed
wants to merge 1 commit into from

Conversation

jimgrier
Copy link

  1. Although there is an RWMutex in the mocking structure, it is used inconsistently, leading to the Go race detector to cause sporadic data race errors while unit testing.

  2. The ...ReturnsOnCall() method allows for the creation of a map such that one may specify return values on arbitrary calls to the mocked function. For example, you can request that the first two invocations fail, followed by a successful call, in order to check out retry behavior. The problem is that once this map is set, the default return value for the mocked function call becomes all nils and not what was intended. This led to situations where it was necessary to call the mocked function first and save the returns, then set the map values for failures to one offset from the desired index, and set ANY indices that might be hit other to the saved default value. This violates the Principle of Least Surprise.

…p such that one may specify return values on arbitrary calls to the mocked function. For example, you can request that the first two invocations fail, followed by a successful call, in order to check out retry behavior. The problem is that once this map is set, the default return value for the mocked function call becomes all nils and not what was intended. This led to situations where it was necessary tp call the mocked function first and save the returns, then set the map values for failures to one offset from the desired index, and set ANY indices that might be hit other to the saved default value.

2. Although there is an RWMutex in the mocking structure, it is used inconsistently, leading to the Go race detector to cause sporadic data race errors while unit testing.
@joefitzgerald
Copy link
Collaborator

https://github.com/maxbrunsfeld/counterfeiter/releases/tag/v6.0.0 does away with the use of ast for code generation. Is this still an issue?

joefitzgerald added a commit that referenced this pull request Oct 16, 2018
Does not help you if you mutate the stub directly. We will need to add a stub setter / clearer to assist people who are directly setting the Stub.

- #44
- #84
@joefitzgerald
Copy link
Collaborator

@jimgrier could you articulate in more detail what you mean by item 2 in your description, above?

@joefitzgerald
Copy link
Collaborator

I am going to close this as fixed, and suggest that we think about item 2 from the description separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants