2018-05-18 21:36:43 +00:00
|
|
|
describe("Balancer chash", function()
|
2021-01-04 20:01:55 +00:00
|
|
|
after_each(function()
|
|
|
|
reset_ngx()
|
|
|
|
end)
|
2018-05-18 21:36:43 +00:00
|
|
|
|
|
|
|
describe("balance()", function()
|
|
|
|
it("uses correct key for given backend", function()
|
2021-01-04 20:01:55 +00:00
|
|
|
ngx.var = { request_uri = "/alma/armud"}
|
|
|
|
local balancer_chash = require_without_cache("balancer.chash")
|
2018-05-18 21:36:43 +00:00
|
|
|
|
|
|
|
local resty_chash = package.loaded["resty.chash"]
|
|
|
|
resty_chash.new = function(self, nodes)
|
|
|
|
return {
|
|
|
|
find = function(self, key)
|
|
|
|
assert.equal("/alma/armud", key)
|
|
|
|
return "10.184.7.40:8080"
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
local backend = {
|
2018-11-10 23:30:06 +00:00
|
|
|
name = "my-dummy-backend", upstreamHashByConfig = { ["upstream-hash-by"] = "$request_uri" },
|
2018-05-18 21:36:43 +00:00
|
|
|
endpoints = { { address = "10.184.7.40", port = "8080", maxFails = 0, failTimeout = 0 } }
|
|
|
|
}
|
|
|
|
local instance = balancer_chash:new(backend)
|
|
|
|
|
2018-05-30 21:14:28 +00:00
|
|
|
local peer = instance:balance()
|
|
|
|
assert.equal("10.184.7.40:8080", peer)
|
2018-05-18 21:36:43 +00:00
|
|
|
end)
|
|
|
|
end)
|
2018-04-20 03:02:22 +00:00
|
|
|
end)
|