Mock time
See original GitHub issueWe should make sure that there is only one source of time in Textual.
Ideally App should have get_time
function which returns the current time.
We should have a mechanism to replace the system time with an alternative time, which we can use to ensure tests are deterministic.
Suggest that App accepts a get_time
callable which will replace monotonic
Issue Analytics
- State:
- Created a year ago
- Comments:9
Top Results From Across the Web
Mock time in tests - Hackage
Allows to mock out Data.Time.getCurrentTime and Control.Concrurent.threadDelay. [Skip to Readme]. Modules. [Index] [Quick Jump]. Control.
Read more >Test::MockTime - Replaces actual time with simulated time
This module was created to enable test suites to test code at specific points in time. Specifically it overrides localtime, gmtime and time...
Read more >Mock time.sleep and time.time to enhace your tests. · GitHub
A typical mock case is changing the output of time, date and datetime methods. You may be tempted to make a time.sleep of...
Read more >Timer Mocks - Jest
To do this, we're going to use Jest's timer control APIs to fast-forward time right in the middle of the test: jest.useFakeTimers();
Read more >Mocking time and testing event loops in Go - Dmitry Frank
Mocking time and testing event loops in Go ... when I need to mock time, it's usually to test some event loop with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I don’t think there is any performance issue in getting the time, it’s a fairly lean operation:
I think I see where you are going with an orchestrator. I hadn’t considered
asyncio.sleep
as a sneaky source of time that we can’t control.But I suspect 60fps is going to be a performance drain. If I have understood you correctly, it would have to be running all the time. Even if it wasn’t doing anything, thats still a cpu drain.
How about we move all explicit calls to get the time in to app, which we can mock. We also move the responsibility for
asyncio.sleep
in to App. In normal operation we defer toasyncio.sleep
, but for testing we base it on our mocked time.I’m thinking a method like
App.advance_time(delta)
which moves the clock forward and wakes up any sleeping cooroutines.Let’s have a chat about it tomorrow. It’s a tricky topic, and it’s worth having the 3 of us on this.
Did we solve your problem?
Glad we could help!