-
Notifications
You must be signed in to change notification settings - Fork 181
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
Implementing "tick" to avoid using sleep #127
Comments
Wouldn't be opposed to a feature like that. Marking as HelpWanted. |
|
Thanks, I haven't come across freezegun before. From a quick look at the docs it appears to mock the functions that get time, but not |
@bmerry fakeredis/fakeredis/_server.py Lines 818 to 820 in e04fc6e
This method is mocked by fakeredis/test/test_fakeredis.py Lines 3994 to 4001 in dcf0c89
Could be rewritten as @freeze_time(as_kwarg='frozen_time')
def test_expireat_should_expire_key_by_timestamp(r, frozen_time):
r.set('foo', 'bar')
assert r.get('foo') == b'bar'
r.expireat('foo', int(time() + 1))
frozen_time.tick(1.5)
assert r.get('foo') is None
assert r.expire('bar', 1) is False |
In the case of internal usages of fakeredis/fakeredis/_server.py Line 2592 in dcf0c89
They can be mocked with |
I think one problem is that the tests run against both real redis and fake redis to ensure that the tests have correct expectations, and of course freezegun won't work with real redis. But I can probably build a pytest fixture to do the mocking in the appropriate cases, which would at least halve the sleep time in tests. I'll take a look at some point when I have free time - thanks for the suggestion. |
FYI I built a faster alternative to freezegun called time-machine. See https://adamj.eu/tech/2020/06/03/introducing-time-machine/ . |
@adamchainz sadly I'm trying this right now and does not seem to work 😢
|
@slothyrulez Hmm I am afraid I can't see why exactly. It looks like fakeredis (the new maintained repo) calls time-machine definitely mocks Maybe the above code path isn't running, so the server |
Ummmmm, should I open a discussion on time-machine or in fakeredis ? Definitively, thanks for your response @adamchainz |
I think this is an issue with how fakeredis reads the time. I’d only want a time-machine issue if you can show there’s an underlying cause that needs a fix. |
|
Cross-posting here for future visibility cunla/fakeredis-py#253 |
freezegun doesn't work with aioredis, unfortunately. |
Great work on this library. Just wondering, have you considered adding a
tick
method or some sort of frozen time mode to FakeRedis that allows programmatic advancing of time to avoid using an actualsleep
in the test code?The text was updated successfully, but these errors were encountered: