Skip to content

Commit

Permalink
Merge pull request #762 from 3scale/rate-limit-redis-shdict
Browse files Browse the repository at this point in the history
[spec] unify style of rate limit policy test
  • Loading branch information
mikz authored Jun 13, 2018
2 parents c00c5e3 + 3efa8b1 commit c01403d
Show file tree
Hide file tree
Showing 2 changed files with 244 additions and 221 deletions.
12 changes: 7 additions & 5 deletions gateway/src/apicast/policy/rate_limit/rate_limit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,12 @@ function _M:access(context)
if comerr == "rejected" then
ngx.log(ngx.WARN, "Requests over the limit.")
error(self.error_settings, "limits_exceeded")
return
return nil, 'limits exceeded'
else
ngx.log(ngx.ERR, "failed to limit traffic: ", comerr)
error(self.error_settings, "configuration_issue")
return nil, comerr or 'invalid configuration'
end
ngx.log(ngx.ERR, "failed to limit traffic: ", comerr)
error(self.error_settings, "configuration_issue")
return
end

for i, lim in ipairs(limiters) do
Expand All @@ -205,6 +206,7 @@ function _M:access(context)
ngx.sleep(delay)
end

return true, delay
end

local function checkin(_, ctx, time, semaphore, redis_url, error_settings)
Expand Down Expand Up @@ -246,7 +248,7 @@ function _M:log()
if limiters and next(limiters) ~= nil then
local semaphore = ngx_semaphore.new()
ngx.timer.at(0, checkin, ngx.ctx, ngx.var.request_time, semaphore, self.redis_url, self.error_settings)
semaphore:wait(10)
return semaphore:wait(10)
end
end

Expand Down
Loading

0 comments on commit c01403d

Please sign in to comment.