From 880b3dc5f17aaeb49d0e867245bf5ca15262d915 Mon Sep 17 00:00:00 2001 From: Alexander Maret-Huskinson Date: Fri, 30 Aug 2019 19:08:03 +0200 Subject: [PATCH] Fixed test findings. --- internal/ingress/annotations/annotations_test.go | 7 ++++--- rootfs/etc/nginx/lua/balancer/sticky_balanced.lua | 6 +++--- rootfs/etc/nginx/lua/balancer/sticky_persistent.lua | 2 +- rootfs/etc/nginx/lua/test/balancer/sticky_test.lua | 12 ++++++------ 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/internal/ingress/annotations/annotations_test.go b/internal/ingress/annotations/annotations_test.go index 2eac8c234..a496cd9ba 100644 --- a/internal/ingress/annotations/annotations_test.go +++ b/internal/ingress/annotations/annotations_test.go @@ -33,6 +33,7 @@ var ( annotationSecureVerifyCACert = parser.GetAnnotationWithPrefix("secure-verify-ca-secret") annotationPassthrough = parser.GetAnnotationWithPrefix("ssl-passthrough") annotationAffinityType = parser.GetAnnotationWithPrefix("affinity") + annotationAffinityMode = parser.GetAnnotationWithPrefix("affinity-mode") annotationCorsEnabled = parser.GetAnnotationWithPrefix("enable-cors") annotationCorsAllowMethods = parser.GetAnnotationWithPrefix("cors-allow-methods") annotationCorsAllowHeaders = parser.GetAnnotationWithPrefix("cors-allow-headers") @@ -205,8 +206,8 @@ func TestAffinitySession(t *testing.T) { {map[string]string{annotationAffinityType: "cookie", annotationAffinityMode: "balanced", annotationAffinityCookieName: "route"}, "cookie", "balanced", "route"}, {map[string]string{annotationAffinityType: "cookie", annotationAffinityMode: "persistent", annotationAffinityCookieName: "route1"}, "cookie", "persistent", "route1"}, {map[string]string{annotationAffinityType: "cookie", annotationAffinityMode: "balanced", annotationAffinityCookieName: ""}, "cookie", "balanced", "INGRESSCOOKIE"}, - {map[string]string{}, "", ""}, - {nil, "", ""}, + {map[string]string{}, "", "", ""}, + {nil, "", "", ""}, } for _, foo := range fooAnns { @@ -214,7 +215,7 @@ func TestAffinitySession(t *testing.T) { r := ec.Extract(ing).SessionAffinity t.Logf("Testing pass %v %v", foo.affinitytype, foo.name) - if (r.Mode != foo.affinitymode) { + if r.Mode != foo.affinitymode { t.Errorf("Returned %v but expected %v for Name", r.Mode, foo.affinitymode) } diff --git a/rootfs/etc/nginx/lua/balancer/sticky_balanced.lua b/rootfs/etc/nginx/lua/balancer/sticky_balanced.lua index 52d097388..e2132dc08 100644 --- a/rootfs/etc/nginx/lua/balancer/sticky_balanced.lua +++ b/rootfs/etc/nginx/lua/balancer/sticky_balanced.lua @@ -1,7 +1,7 @@ -- An affinity mode which makes sure connections are rebalanced when a deployment is scaled. -- The advantage of this mode is that the load on the pods will be redistributed. --- The drawback of this mode is that, when scaling up a deployment, roughly (n-c)/n users --- will lose their session, where c is the current number of pods and n is the new number of +-- The drawback of this mode is that, when scaling up a deployment, roughly (n-c)/n users +-- will lose their session, where c is the current number of pods and n is the new number of -- pods. -- local balancer_sticky = require("balancer.sticky") @@ -27,7 +27,7 @@ function _M.new(self, backend) setmetatable(o, self) self.__index = self - + balancer_sticky.sync(o, backend) return o diff --git a/rootfs/etc/nginx/lua/balancer/sticky_persistent.lua b/rootfs/etc/nginx/lua/balancer/sticky_persistent.lua index 0bd6dc8d0..993eb8c8c 100644 --- a/rootfs/etc/nginx/lua/balancer/sticky_persistent.lua +++ b/rootfs/etc/nginx/lua/balancer/sticky_persistent.lua @@ -20,7 +20,7 @@ function _M.new(self, backend) setmetatable(o, self) self.__index = self - + balancer_sticky.sync(o, backend) return o diff --git a/rootfs/etc/nginx/lua/test/balancer/sticky_test.lua b/rootfs/etc/nginx/lua/test/balancer/sticky_test.lua index e9503dc5f..53f1c1ea7 100644 --- a/rootfs/etc/nginx/lua/test/balancer/sticky_test.lua +++ b/rootfs/etc/nginx/lua/test/balancer/sticky_test.lua @@ -261,8 +261,8 @@ describe("Sticky", function() assert.spy(s).was_not_called() end - it("does not set a cookie", test_no_cookie(sticky_balanced)) - it("does not set a cookie", test_no_cookie(sticky_persistent)) + it("does not set a cookie", function() test_no_cookie(sticky_balanced) end) + it("does not set a cookie", function() test_no_cookie(sticky_persistent) end) local function test_correct_endpoint(sticky) local sticky_balancer_instance = sticky:new(test_backend) @@ -340,16 +340,16 @@ describe("Sticky", function() end it("changes upstream when change_on_failure option is true", function() - test(sticky_balanced, 'balanced', true) + test(sticky_balanced, true) end) it("changes upstream when change_on_failure option is true", function() - test(sticky_balanced, 'balanced', false) + test(sticky_balanced, false) end) it("changes upstream when change_on_failure option is true", function() - test(sticky_persistent, 'balanced', true) + test(sticky_persistent, true) end) it("changes upstream when change_on_failure option is true", function() - test(sticky_persistent, 'balanced', false) + test(sticky_persistent, false) end) end) end)