-
Notifications
You must be signed in to change notification settings - Fork 815
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
Removed replication mocks #4883
Removed replication mocks #4883
Conversation
Pull Request Test Coverage Report for Build 0181cd19-b304-431d-a72d-bd3f7075fa6a
💛 - Coveralls |
While I'm largely in favor of this, one advantage of lines like s.taskExecutor.EXPECT().execute(replicationTask, true).Return(0, nil).Times(1) that is being lost is the ability to require that those mocks are used. the current fakes are silent about non-use. Which may be entirely reasonable for those tests, I haven't read closely enough yet. Would there be any simple way to require them though? Unused fakes leading to gradual drift and misunderstanding of tests has been a pretty big problem in past projects in my experience, and the "must be used" check is a pretty simple way to lock that down. |
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.
Tbh I'm not sure this is significantly easier to maintain fakes in the long-term, but 👍
6d187bc
to
4c63863
Compare
Yes, you are entirely correct on this point. I have added a check back, so that test semantics would remain the same.
Could you elaborate on what you mean by "gradual drift"? Some thoughts in general. Cadence seems to be build in a very "Java" like style. Interfaces comes first, necessary or not. Along with mocks. It seems to be contrary to many best practices offered by go-lang. Specifically to this discussion: return structs, accept interfaces that are often defined where they are used and only with a subset of actually needed methods. Smaller interfaces are easily faked, making unit-tests easier to write. IMO it is very counter-productive to write unit-tests where 90% of the test is mocking complex dependencies. Small interfaces along with fakes, makes unit testing much easier. I would very much like us go into that direction. Of course mocks still have their place. Especially for Facade style interfaces exposed by packages. One good example - all persistence managers and their corresponding mocks. However, all dependencies that can be modeled as a state or used completely within a single package internally can probably be simplified as fakes instead. Feel free to argue on those topics, I'm interested in other opinions as well. |
I pretty much completely agree, and yeah - the up-front interface-and-mock habits lead to very artificial tests. I'd much prefer to mock less, further away from the code actually being tested, because it means you're getting additional checks of "this leads to behavior X which is the actual goal of this method, even though it's 3 calls away". Super fine-grained mocks are often hard to read and understand, and tend to break at the smallest touch which makes them a real pain during refactoring (rather than helping refactoring). Re fakes and "drift": largely two things.
^ and those often combine to create a gradual loss of accuracy. A lot of which can be traced back to their frequent inability to ensure they're relevant. None of which is unfixable. I just want us to establish a strong habit of e.g. "if you have a fake in a test, it must be relevant", with only rare exceptions. |
What changed?
Removed all replication mocks.
Why?
They are either not used at all or used internally in a couple of places.
For them we can use light-weigh fakes instead and have less code.
How did you test it?
Existing tests should pass.
Potential risks
Release notes
Documentation Changes