spulec / freezegun

Let your Python tests travel through time
Apache License 2.0
4.15k stars 269 forks source link

Freezing monotonic time implicitly causes problems #384

Open tzoiker opened 3 years ago

tzoiker commented 3 years ago

I have faced the very same problem as in #383, but in another context and it was very painful to debug.

The problem was aggravated by the fact that I didn't pin the minor version of freezegun in the testing pipeline so that when 1.1.0 was released tests started to fail unexpectedly.

Some suggestions:

Thank you for consideration.

shughes-uk commented 3 years ago

This also causes issues with celery during tests due to kombu relying on monotonic https://github.com/celery/kombu/blob/master/kombu/transport/virtual/base.py#L950-L965

Manifests as RuntimeError: Worker thread failed to exit within the allocated timeout. Consider raisingshutdown_timeoutif your tasks take longer to execute.

Workaround for now is we locked freezegun at 1.0.0

ExpLog commented 2 years ago

This causes all manner of problems with aiokafka as well, which are nearly impossible to debug, as it apparently just hangs when you give it timeouts.

Be very careful what you wrap with freezetime if you're using async.

My solution for now was to wrap factory fixtures with freezetime instead of wrapping tests.