-
Notifications
You must be signed in to change notification settings - Fork 899
Implement IDisposable in OdbBackend #713
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
Conversation
It does make sense; the lifecycle for an OdbBackend is such that libgit2 itself is the one who disposes the backend, not the caller. |
Yes, unless you're writing your own and want to properly test it (my case). Anyway, the framework can do nice things with disposables, so why not tell it it is one? |
Well, maybe I'm not understanding what you want to do. But if you were to make that I guess I just don't understand what problem you're trying to solve. |
Implement my own using (var be = new MyOdbBackend())
{
// test
} Even though it does implement Dispose() In what scenarios do you see ppl going to dispose the backend and expecting libgit2 not to throw??? |
Yes, but it's not clear to me why you want to do that. We also implement our own OdbBackends, we also unit test them, and making them Right now: there are no scenarios where people can dispose the backend. Only libgit2 can dispose the backend. That's why the |
Because testing a backend through libgit2 is not unit testing :) there are a few behaviors I'm testing directly, at least as smoke tests. It would be easier to have a disposable object implement Feel free to close this if the answer is still no. |
Similar to #528 (comment), perhaps we should reserve
Nothing prevents you from making |
Free like in C or in Beer ? :) |
And good point @dahlbyk |
Aha aha - I see. Yeah, I think that what @dahlbyk is suggesting is the best solution, that:
Does this seem reasonable? |
@ethomson yep, but try finding a better name than |
Okay, that's fair. I'm partial to Thanks for your patience in explaining this problem; apologies for being On Mon, May 19, 2014 at 4:09 PM, Itamar Syn-Hershko <
|
Ok. I turned this issue into a PR with a proposal. I changed the way Previous implementation was allowing the consumer to override The change allows the following:
|
@synhershko I wouldn't recommend this kind of unit testing. AFAIK, Leveraging the backend by itself, outside of the libgit2sharp/libgit2 ecosystem would short-circuit the memory life cycle and lead to memory leaks. Well, at least this is my understanding of the code... and I may be completely wrong. /cc @ethomson |
{ | ||
if (IntPtr.Zero != nativeBackendPointer) | ||
if (nativeBackendPointer == IntPtr.Zero) |
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.
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.
I propose to rename the variable to pointerBackendNative
This looks good. The only thing I would say is that sometimes with Dispose methods there are bugs where the environment invokes the Dispose method twice. It might be interesting to modify the test case to check for a stronger guarantee -- that the dispose count on the MockOdbBackend is exactly 1 after the Repository is disposed, rather than just checking that it has been invoked at least once, which is what is happening now. This is only a suggestion and should not hold up this PR, because what you have here is fine as is as well. |
@phkelley You're right. Fixed! Thanks for your 👀 ! |
Seeing how it implements Dispose, it doesn't make sense not to have it implement IDisposable