From 67f28fe62db3653bfce63d652e998eb525fc35db Mon Sep 17 00:00:00 2001 From: Jason Le Date: Thu, 8 Dec 2016 17:08:39 -0500 Subject: [PATCH] Speed up rate limiting test in test_external. Patches out the `time.sleep` and mocks the `time.time` to one second ahead. Resolves #2239. --- zerver/tests/test_external.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/zerver/tests/test_external.py b/zerver/tests/test_external.py index bd2c0627c1..be5db884d8 100644 --- a/zerver/tests/test_external.py +++ b/zerver/tests/test_external.py @@ -18,7 +18,6 @@ from zerver.lib.test_classes import ( ZulipTestCase, ) from zerver.models import get_user_profile_by_email -from zerver.lib.test_runner import slow import DNS import mock @@ -100,7 +99,6 @@ class RateLimitTests(ZulipTestCase): newlimit = int(result['X-RateLimit-Remaining']) self.assertEqual(limit, newlimit + 1) - @slow('has to sleep to work') def test_hit_ratelimits(self): # type: () -> None email = "cordelia@zulip.com" @@ -120,8 +118,7 @@ class RateLimitTests(ZulipTestCase): # We actually wait a second here, rather than force-clearing our history, # to make sure the rate-limiting code automatically forgives a user # after some time has passed. - time.sleep(1) + with mock.patch('time.time', return_value=(time.time() + 1)): + result = self.send_api_message(email, "Good message") - result = self.send_api_message(email, "Good message") - - self.assert_json_success(result) + self.assert_json_success(result)