regression test
This commit is contained in:
parent
6f7b66fc7d
commit
8f5fa78e1a
2 changed files with 40 additions and 1 deletions
|
@ -207,7 +207,7 @@ local function get_balancer()
|
||||||
|
|
||||||
balancer = balancers[alternative_backend_name]
|
balancer = balancers[alternative_backend_name]
|
||||||
end
|
end
|
||||||
|
|
||||||
ngx.ctx.balancer = balancer
|
ngx.ctx.balancer = balancer
|
||||||
|
|
||||||
return balancer
|
return balancer
|
||||||
|
@ -266,6 +266,7 @@ if _TEST then
|
||||||
_M.get_implementation = get_implementation
|
_M.get_implementation = get_implementation
|
||||||
_M.sync_backend = sync_backend
|
_M.sync_backend = sync_backend
|
||||||
_M.route_to_alternative_balancer = route_to_alternative_balancer
|
_M.route_to_alternative_balancer = route_to_alternative_balancer
|
||||||
|
_M.get_balancer = get_balancer
|
||||||
end
|
end
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
|
|
@ -86,6 +86,44 @@ describe("Balancer", function()
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
describe("get_balancer()", function()
|
||||||
|
it("always returns the same balancer for given request context", function()
|
||||||
|
local backend = {
|
||||||
|
name = "my-dummy-app-6", ["load-balance"] = "ewma",
|
||||||
|
alternativeBackends = { "my-dummy-canary-app-6" },
|
||||||
|
endpoints = { { address = "10.184.7.40", port = "8080", maxFails = 0, failTimeout = 0 } },
|
||||||
|
trafficShapingPolicy = {
|
||||||
|
weight = 0,
|
||||||
|
header = "",
|
||||||
|
headerValue = "",
|
||||||
|
cookie = ""
|
||||||
|
},
|
||||||
|
}
|
||||||
|
local canary_backend = {
|
||||||
|
name = "my-dummy-canary-app-6", ["load-balance"] = "ewma",
|
||||||
|
alternativeBackends = { "my-dummy-canary-app-6" },
|
||||||
|
endpoints = { { address = "11.184.7.40", port = "8080", maxFails = 0, failTimeout = 0 } },
|
||||||
|
trafficShapingPolicy = {
|
||||||
|
weight = 5,
|
||||||
|
header = "",
|
||||||
|
headerValue = "",
|
||||||
|
cookie = ""
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
balancer.sync_backend(backend)
|
||||||
|
balancer.sync_backend(canary_backend)
|
||||||
|
|
||||||
|
mock_ngx({ var = { proxy_upstream_name = backend.name } })
|
||||||
|
|
||||||
|
local expected = balancer.get_balancer()
|
||||||
|
|
||||||
|
for i = 1,50,1 do
|
||||||
|
assert.are.same(expected, balancer.get_balancer())
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
describe("route_to_alternative_balancer()", function()
|
describe("route_to_alternative_balancer()", function()
|
||||||
local backend, _balancer
|
local backend, _balancer
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue