-
Notifications
You must be signed in to change notification settings - Fork 179
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
Resolve Dummy Lazy values lazily #1656
Comments
Interesting... I was about to say "but they are lazy", because
I guess we could make them really lazy. But what would be the benefit? Maybe a small performance improvement, but I doubt it would make a big difference. |
The real reason I filed this issue is not the scenario above. The real reason I want it to work this way is because of the test scenarios where
|
What's the problem with these scenarios? Even if what is returned by Unfortunately, in the example you posted, |
I mean I'm bringing this up primarily motivated by efficiency, not correctness, whatever that is. Less electrons moved, less time running tests, less carbon emitted, all that good stuff. So from my particular point of view, its fine for |
A good goal, @TimLovellSmith. Truth be told, I think your version may be superior. If we could be sure there's no downside to changing the behaviour, I think I'd be advocating for the change. But we've been promising to return a Lazy that already has a value, and I worry that the change might break people's tests. |
… and I'm a little afraid that if we were to make the change, I'd be tempted to implement by passing a |
Have we? In How are the dummies made, we just say this:
To me, it doesn't seem to imply that the value is created eagerly.
I don't think it could. The value can only be accessed via the
That's a clever approach, I would never have thought of it! But yeah, it might not be the most efficient, especially with the way we create fake delegates, which is quite slow. |
Ah. Okay, then. Maybe I've been reading it wrong!
IsValueCreated's initial setting would change. But maybe it's not such a big deal. |
I've been thinking about |
How so? Currently when we create a dummy |
That's an interesting point. I didn't consider a similarity between |
The main use for 'IsValueCreated' that I know about is checking whether you really created something so you know whether you have to Dispose it, without accidentally creating one in the process! IMHO if they wrote any code that cares enough to test a boolean value, like this, which is really designed to support scenarios where you don't want to be sure that Value was created shouldn't callers also care enough to handles the 'it can return false' case? Otherwise they should just not even have been testing IsValueCreated... :) Yes my unit test where I use IsValueCreated is somewhat a counterexample, but this is not what I consider a typical use case! [And I do handle the return false value, by failing/passing the test according to my desire. :-) ] |
I'm okay with changing creation to be lazy. |
I think so... But as you said, we won't be in a loop when the value is actually resolved. We just need to make sure to use a new |
I think it'll be empty by the time the |
If you have a lazy, it will be harder to have a loop, because a loop should be taking you back to Lazy, and then nobody will call Value... unless they are doing it, unlazily, as part of initializing something. In which case yes, you might get a loop. But if its that kind of loop, wouldn't it all happen within one loop detecting context already? (Not really sure, trying to convince myself...) |
I think we're unlikely to have a loop within the Lazy resolution, but we recently fixed a bug when a class's constructor took an instance of the class, so weird things do come up. I don't think the proposed change will introduce any problems on that front. |
Labelling as breaking because there's a remote chance that clients are expecting a side effect from the constructor to execute at a particular time, as @thomaslevesque noted in private chat. |
This change has been released as part of FakeItEasy 6.0.0-beta.1. |
Thanks for suggesting this @TimLovellSmith! Look for your name in the release notes! 🥇 |
Woohoo! 🎉 |
I thought of this while reviewing docs for dummies and thinking about how many dummy types/objects might get created.
Wouldn't it be neat if this passed, and in fact a dummy type for WantsToBeDummyed was not actually generated, if Lazy.Value was never called? [A definite possibility when faking objects with 'lazy dependencies].
The text was updated successfully, but these errors were encountered: