Skip to content

Commit

Permalink
tests(rate-limiting) fix rate-limiting access tests and remove old dao
Browse files Browse the repository at this point in the history
  • Loading branch information
bungle authored and hishamhm committed Dec 12, 2018
1 parent 211b90a commit 6ac7a2b
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions spec/03-plugins/24-rate-limiting/04-access_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,12 @@ for _, strategy in helpers.each_strategy() do
describe(fmt("#flaky Plugin: rate-limiting (access) with policy: %s [#%s]", policy, strategy), function()
local bp
local db
local dao

lazy_setup(function()
helpers.kill_all()
flush_redis()

bp, db, dao = helpers.get_db_utils(strategy)
bp, db = helpers.get_db_utils(strategy)

local consumer1 = bp.consumers:insert {
custom_id = "provider_123",
Expand Down Expand Up @@ -380,6 +379,7 @@ for _, strategy in helpers.each_strategy() do
local json = cjson.decode(body)
assert.same({ message = "API rate limit exceeded" }, json)
end)

it("blocks if the only rate-limiting plugin existing is per consumer and not per API", function()
for i = 1, 6 do
local res = GET("/status/200?apikey=apikey122", {
Expand Down Expand Up @@ -418,7 +418,6 @@ for _, strategy in helpers.each_strategy() do
helpers.kill_all()

assert(db:truncate())
dao:truncate_tables()

local route1 = bp.routes:insert {
hosts = { "failtest1.com" },
Expand Down Expand Up @@ -459,7 +458,7 @@ for _, strategy in helpers.each_strategy() do
assert.are.same(5, tonumber(res.headers["x-ratelimit-remaining-minute"]))

-- Simulate an error on the database
assert(dao.db:drop_table("ratelimiting_metrics"))
assert(db.connector:query("DROP TABLE ratelimiting_metrics"))

-- Make another request
local _, body = GET("/status/200", {
Expand All @@ -470,8 +469,9 @@ for _, strategy in helpers.each_strategy() do
assert.same({ message = "An unexpected error occurred" }, json)

db:reset()
bp, db, dao = helpers.get_db_utils(strategy)
bp, db = helpers.get_db_utils(strategy)
end)

it("keeps working if an error occurs", function()
local res = GET("/status/200", {
headers = { Host = "failtest2.com" },
Expand All @@ -481,7 +481,7 @@ for _, strategy in helpers.each_strategy() do
assert.are.same(5, tonumber(res.headers["x-ratelimit-remaining-minute"]))

-- Simulate an error on the database
assert(dao.db:drop_table("ratelimiting_metrics"))
assert(db.connector:query("DROP TABLE ratelimiting_metrics"))

-- Make another request
local res = GET("/status/200", {
Expand All @@ -492,7 +492,7 @@ for _, strategy in helpers.each_strategy() do
assert.falsy(res.headers["x-ratelimit-remaining-minute"])

db:reset()
bp, db, dao = helpers.get_db_utils(strategy)
bp, db = helpers.get_db_utils(strategy)
end)
end)

Expand All @@ -503,7 +503,6 @@ for _, strategy in helpers.each_strategy() do
helpers.kill_all()

assert(db:truncate())
dao:truncate_tables()

local service1 = bp.services:insert()

Expand Down Expand Up @@ -552,6 +551,7 @@ for _, strategy in helpers.each_strategy() do
local json = cjson.decode(body)
assert.same({ message = "An unexpected error occurred" }, json)
end)

it("keeps working if an error occurs", function()
local res = GET("/status/200", {
headers = { Host = "failtest4.com" },
Expand Down Expand Up @@ -594,7 +594,7 @@ for _, strategy in helpers.each_strategy() do
}))
end)

describe("expires a counter", function()
it("expires a counter", function()
local res = GET("/status/200", {
headers = { Host = "expire1.com" },
}, 200)
Expand Down

0 comments on commit 6ac7a2b

Please sign in to comment.