Merge pull request #6600 from nic-6443/backend-sync-503-fix

Bugfix: some requests fail with 503 when nginx reload
This commit is contained in:
Kubernetes Prow Robot 2020-12-23 09:02:26 -08:00 committed by GitHub
commit 7732aec3c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 66 additions and 16 deletions

View file

@ -1,3 +1,5 @@
local cjson = require("cjson.safe")
local util = require("util")
local balancer, expected_implementations, backends
local original_ngx = ngx
@ -339,7 +341,9 @@ describe("Balancer", function()
local mock_instance = { sync = function(backend) end }
setmetatable(mock_instance, implementation)
implementation.new = function(self, backend) return mock_instance end
local s = spy.on(implementation, "new")
assert.has_no.errors(function() balancer.sync_backend(backend) end)
assert.spy(s).was_called_with(implementation, expected_backend)
stub(mock_instance, "sync")
assert.has_no.errors(function() balancer.sync_backend(backend) end)
assert.stub(mock_instance.sync).was_called_with(mock_instance, expected_backend)
@ -364,9 +368,11 @@ describe("Balancer", function()
local mock_instance = { sync = function(backend) end }
setmetatable(mock_instance, implementation)
implementation.new = function(self, backend) return mock_instance end
assert.has_no.errors(function() balancer.sync_backend(backend) end)
local s = spy.on(implementation, "new")
assert.has_no.errors(function() balancer.sync_backend(util.deepcopy(backend)) end)
assert.spy(s).was_called_with(implementation, expected_backend)
stub(mock_instance, "sync")
assert.has_no.errors(function() balancer.sync_backend(backend) end)
assert.has_no.errors(function() balancer.sync_backend(util.deepcopy(backend)) end)
assert.stub(mock_instance.sync).was_called_with(mock_instance, expected_backend)
end)
@ -400,4 +406,38 @@ describe("Balancer", function()
assert.stub(mock_instance.sync).was_called_with(mock_instance, backend)
end)
end)
describe("sync_backends()", function()
after_each(function()
reset_ngx()
end)
it("sync backends", function()
backends = {
{
name = "access-router-production-web-80", port = "80", secure = false,
sslPassthrough = false,
endpoints = {
{ address = "10.184.7.40", port = "8080", maxFails = 0, failTimeout = 0 },
{ address = "10.184.97.100", port = "8080", maxFails = 0, failTimeout = 0 },
{ address = "10.184.98.239", port = "8080", maxFails = 0, failTimeout = 0 },
},
sessionAffinityConfig = { name = "", cookieSessionAffinity = { name = "" } },
trafficShapingPolicy = {
weight = 0,
header = "",
headerValue = "",
cookie = ""
},
}
}
mock_ngx({ var = { proxy_upstream_name = "access-router-production-web-80" }, ctx = { } })
ngx.shared.configuration_data:set("backends", cjson.encode(backends))
reset_balancer()
balancer.init_worker()
assert.not_equal(balancer.get_balancer(), nil)
end)
end)
end)