Skip to content

Commit

Permalink
tests(proxy-cache) fix flaky tests (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamhm authored Dec 20, 2019
1 parent 7b37b27 commit 35cc5da
Showing 1 changed file with 45 additions and 49 deletions.
94 changes: 45 additions & 49 deletions spec/04-invalidations_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ describe("proxy-cache invalidations via: " .. strategy, function()
local plugin2
local bp

local wait_for_propagation

setup(function()
bp = helpers.get_db_utils(strategy, nil, {"proxy-cache"})

Expand Down Expand Up @@ -91,10 +89,6 @@ describe("proxy-cache invalidations via: " .. strategy, function()
client_2 = helpers.http_client("127.0.0.1", 9000)
admin_client_1 = helpers.http_client("127.0.0.1", 8001)
admin_client_2 = helpers.http_client("127.0.0.1", 9001)

wait_for_propagation = function()
ngx.sleep(POLL_INTERVAL + db_update_propagation)
end
end)

teardown(function()
Expand Down Expand Up @@ -201,16 +195,15 @@ describe("proxy-cache invalidations via: " .. strategy, function()

assert.res_status(204, res)

-- wait for propagation
wait_for_propagation()

-- assert that the entity was purged from the second instance
res = assert(admin_client_2:send {
method = "GET",
path = "/proxy-cache/" .. plugin1.id .. "/caches/" .. cache_key,
})

assert.res_status(404, res)
helpers.wait_until(function()
-- assert that the entity was purged from the second instance
res = admin_client_2:send {
method = "GET",
path = "/proxy-cache/" .. plugin1.id .. "/caches/" .. cache_key,
}

return res and res.status == 404
end, 10)

-- refresh and purge with our second endpoint
res_1 = assert(client_1:send {
Expand Down Expand Up @@ -244,16 +237,15 @@ describe("proxy-cache invalidations via: " .. strategy, function()

assert.res_status(204, res)

-- wait for propagation
wait_for_propagation()

-- assert that the entity was purged from the second instance
res = assert(admin_client_2:send {
method = "GET",
path = "/proxy-cache/" .. cache_key,
})

assert.res_status(404, res)
helpers.wait_until(function()
-- assert that the entity was purged from the second instance
res = admin_client_2:send {
method = "GET",
path = "/proxy-cache/" .. cache_key,
}

return res and res.status == 404
end, 10)

end)

Expand All @@ -265,7 +257,7 @@ describe("proxy-cache invalidations via: " .. strategy, function()

assert.res_status(200, res)

local res = assert(admin_client_2:send {
res = assert(admin_client_2:send {
method = "GET",
path = "/proxy-cache/" .. plugin2.id .. "/caches/" .. cache_key2,
})
Expand All @@ -274,28 +266,32 @@ describe("proxy-cache invalidations via: " .. strategy, function()
end)

it("propagates global purges", function()
local res = assert(admin_client_1:send {
method = "DELETE",
path = "/proxy-cache/",
})

assert.res_status(204, res)

wait_for_propagation()

local res = assert(admin_client_1:send {
method = "GET",
path = "/proxy-cache/" .. plugin2.id .. "/caches/" .. cache_key2,
})

assert.res_status(404, res)

local res = assert(admin_client_2:send {
method = "GET",
path = "/proxy-cache/" .. plugin2.id .. "/caches/" .. cache_key2,
})

assert.res_status(404, res)
do
local res = assert(admin_client_1:send {
method = "DELETE",
path = "/proxy-cache/",
})

assert.res_status(204, res)
end

helpers.wait_until(function()
local res = admin_client_1:send {
method = "GET",
path = "/proxy-cache/" .. plugin2.id .. "/caches/" .. cache_key2,
}

return res and res.status == 404
end, 10)

helpers.wait_until(function()
local res = admin_client_2:send {
method = "GET",
path = "/proxy-cache/" .. plugin2.id .. "/caches/" .. cache_key2,
}

return res and res.status == 404
end, 10)
end)
end)
end)
Expand Down

0 comments on commit 35cc5da

Please sign in to comment.