question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

We 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:closed
  • Created a year ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
willmcgugancommented, May 12, 2022

I don’t think there is any performance issue in getting the time, it’s a fairly lean operation:

>>> monotonic()-monotonic()
-1.1669471859931946e-06

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 to asyncio.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.

0reactions
github-actions[bot]commented, Oct 25, 2022

Did we solve your problem?

Glad we could help!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found