Session Affinity ChangeOnFailure should be boolean

This commit is contained in:
Elvin Efendi 2019-06-06 11:02:51 -04:00
parent c6c6f51006
commit 83f2acbe38
5 changed files with 15 additions and 16 deletions

View file

@ -96,7 +96,7 @@ function _M.balance(self)
if upstream_from_cookie ~= nil then
-- use previous upstream if this is the first attempt or previous attempt succeeded
-- or ingress is configured to ignore previous request result
if state_name == nil or self.cookie_session_affinity.changeonfailure == "false" then
if state_name == nil or not self.cookie_session_affinity.change_on_failure then
return upstream_from_cookie
end
end
@ -106,7 +106,7 @@ function _M.balance(self)
-- If previous attempt failed recent upstream can be obtained from ngx.var.upstream_addr.
-- Do nothing if ingress is configured to ignore previous request result.
if state_name ~= nil and self.cookie_session_affinity.changeonfailure == "true" then
if state_name ~= nil and self.cookie_session_affinity.change_on_failure then
local upstream_addr = ngx.var.upstream_addr
failed_upstream = split.get_last_value(upstream_addr)

View file

@ -194,7 +194,7 @@ describe("Sticky", function()
end)
end)
local function get_several_test_backends(changeOnFailure)
local function get_several_test_backends(change_on_failure)
return {
name = "access-router-production-web-80",
endpoints = {
@ -203,7 +203,7 @@ describe("Sticky", function()
},
sessionAffinityConfig = {
name = "cookie",
cookieSessionAffinity = { name = "test_name", hash = "sha1", changeonfailure = changeOnFailure }
cookieSessionAffinity = { name = "test_name", hash = "sha1", change_on_failure = change_on_failure }
},
}
end
@ -221,7 +221,7 @@ describe("Sticky", function()
end)
context("when request to upstream fails", function()
it("changes upstream when changeOnFailure option is true", function()
it("changes upstream when change_on_failure option is true", function()
-- create sticky cookie
cookie.new = function(self)
local return_obj = {
@ -231,7 +231,7 @@ describe("Sticky", function()
return return_obj, false
end
local options = {'false', 'true'}
local options = {false, true}
for _, option in ipairs(options) do
local sticky_balancer_instance = sticky:new(get_several_test_backends(option))
@ -250,11 +250,11 @@ describe("Sticky", function()
for _ = 1, 100 do
local new_upstream = sticky_balancer_instance:balance()
if option == 'false' then
-- upstream should be the same inspite of error, if changeOnFailure option is false
if option == false then
-- upstream should be the same inspite of error, if change_on_failure option is false
assert.equal(new_upstream, old_upstream)
else
-- upstream should change after error, if changeOnFailure option is true
-- upstream should change after error, if change_on_failure option is true
assert.not_equal(new_upstream, old_upstream)
end
end