-
Couldn't load subscription status.
- Fork 1.4k
ZIO Test: Implement TestClock#advance #3304
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
|
Makes me wonder if we should add some sort of It would look at all the scheduled resumptions, capture the state, and then re-activate them in order, advancing each fiber's No additional schedulings that took place after |
What would happen if we changed |
|
@jdegoes If we always perform a for {
_ <- TestClock.adjust(10.minutes)
_ <- clock.sleep(10.minutes)
} yield assertCompletesWe're adjusting the time by 10 minutes so all effects scheduled to sleep by then will run. But if we do a |
|
@jdegoes That's an interesting idea regarding We could say |
Is it true that the
You are right about that.
I think the current scheme, while maybe unexpected, is at least consistent. A more expected result would be inconsistent. I'd prefer the current state of affairs by far.
|
|
@jdegoes No, I don't think we can say that I agree |
That's really interesting. You'd need to know about all the fibers spawned inside the test, so you could wait until they are all suspended (or terminated). Seems plausible. |
That would be awesome! |
|
Working on the |
|
I believe there was a good reason for a change in TestClock. But now it is a hassle to test anything related to clock. 1. What is the workaround for now?Using sleep after adjust changes the time, but only in the current scope. For the function that follows and calls 2. What would be the general solution to this?One viable option to fix this is to use the |
|
Ok, thanks to @runtologist the answer to the first question is that the observed behavior is just a side effect of #3373 |
Since we changed
TestClockmethods that return time to return the fiber time in #2677, users now need to do asleepcall after anadjustcall to get the updated time from methods likecurrentTime.This PR implements a new combinator
advancethat does anadjustimmediately followed by asleepfor this use case.The one thing we are still potentially missing from this is the ability to adjust the fiber time in an already forked fiber. For example, in:
The result will not reflect the updated time because the forked fiber has its own
FiberRef. This accurately reflects the fact that no sleeping has occurred on the fiber. And in fact allowing modifying the fiber time in situations like this can lead to inconsistent state as in the schedule issue in #2677. We could potentially add anunsafeAdjustmethod to do this but I wonder if that use case is better supported through theMockClock.Copying @runtologist