mirror of https://github.com/zulip/zulip.git
rate_limit tests: Cover RateLimiterLockingException case in rate_limit_user.
This commit is contained in:
parent
1a3297d122
commit
5f88406133
|
@ -793,7 +793,7 @@ def rate_limit_user(request: HttpRequest, user: UserProfile, domain: str) -> Non
|
|||
|
||||
try:
|
||||
incr_ratelimit(entity)
|
||||
except RateLimiterLockingException: # nocoverage # Should add on next rate limit pass
|
||||
except RateLimiterLockingException:
|
||||
logging.warning("Deadlock trying to incr_ratelimit for %s on %s" % (
|
||||
user.id, request.path))
|
||||
# rate-limit users who are hitting the API so hard we can't update our stats.
|
||||
|
|
|
@ -10,6 +10,7 @@ from zerver.lib.rate_limiter import (
|
|||
clear_history,
|
||||
remove_ratelimit_rule,
|
||||
RateLimitedUser,
|
||||
RateLimiterLockingException,
|
||||
)
|
||||
from zerver.lib.zephyr import compute_mit_user_fullname
|
||||
|
||||
|
@ -107,3 +108,13 @@ class RateLimitTests(ZulipTestCase):
|
|||
result = self.send_api_message(email, "Good message")
|
||||
|
||||
self.assert_json_success(result)
|
||||
|
||||
def test_hit_ratelimiterlockingexception(self) -> None:
|
||||
user = self.example_user('cordelia')
|
||||
email = user.email
|
||||
clear_history(RateLimitedUser(user))
|
||||
|
||||
with mock.patch('zerver.decorator.incr_ratelimit',
|
||||
side_effect=RateLimiterLockingException):
|
||||
result = self.send_api_message(email, "some stuff")
|
||||
self.assertEqual(result.status_code, 429)
|
||||
|
|
Loading…
Reference in New Issue