From 9737ffa95fa23dfdebee72f581d72ba88c725a25 Mon Sep 17 00:00:00 2001 From: rpkak <67059904+rpkak@users.noreply.github.com> Date: Tue, 3 Aug 2021 03:00:49 +0200 Subject: [PATCH] Make unstable tests more stable (#1523) Co-authored-by: rpkak --- tests/test_registry.py | 8 ++++---- tests/test_retry.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_registry.py b/tests/test_registry.py index 57f3e1d..0dd7772 100644 --- a/tests/test_registry.py +++ b/tests/test_registry.py @@ -66,10 +66,10 @@ class TestRegistry(RQTestCase): job = queue.enqueue(say_hello) registry.add(job, 5) - self.assertEqual( - registry.get_expiration_time(job), - (datetime.utcnow() + timedelta(seconds=5)).replace(microsecond=0) - ) + time = registry.get_expiration_time(job) + expected_time = (datetime.utcnow() + timedelta(seconds=5)).replace(microsecond=0) + self.assertGreaterEqual(time, expected_time - timedelta(seconds=2)) + self.assertLessEqual(time, expected_time + timedelta(seconds=2)) def test_add_and_remove(self): """Adding and removing job to StartedJobRegistry.""" diff --git a/tests/test_retry.py b/tests/test_retry.py index ad01b37..e8fddeb 100644 --- a/tests/test_retry.py +++ b/tests/test_retry.py @@ -114,7 +114,7 @@ class TestRetry(RQTestCase): # Scheduled time is roughly 5 seconds from now scheduled_time = registry.get_scheduled_time(job) now = datetime.now(timezone.utc) - self.assertTrue(now + timedelta(seconds=4) < scheduled_time < now + timedelta(seconds=6)) + self.assertTrue(now + timedelta(seconds=4) < scheduled_time < now + timedelta(seconds=10)) def test_cleanup_handles_retries(self): """Expired jobs should also be retried"""