TT#165251 redis: force socket close on ping error

Change-Id: I5aa85dbd4fd03d0ea91a6c5f0fb0d23706602196
(cherry picked from commit 9261badc9d)
(cherry picked from commit fc16538d7c)
(cherry picked from commit 8510e54e18)
mr8.5.8
Victor Seva 4 years ago
parent 9104a39e5a
commit 346c6a73fa

@ -66,6 +66,11 @@ end
function NGCPDlgCounters._test_connection(client)
if not client then return nil end
local ok, _ = pcall(client.ping, client);
if not ok then
KSR.info(string.format("close redis server[%d]\n",
client.network.socket:getfd()))
client.network.socket:close()
end
return ok
end

@ -65,6 +65,11 @@ end
local function _test_connection(client)
if not client then return nil end
local ok, _ = pcall(client.ping, client);
if not ok then
KSR.info(string.format("close redis server[%d]\n",
client.network.socket:getfd()))
client.network.socket:close()
end
return ok
end

@ -58,6 +58,11 @@ end
function NGCPRecentCalls._test_connection(client)
if not client then return nil end
local ok, _ = pcall(client.ping, client)
if not ok then
KSR.info(string.format("close redis server[%d]\n",
client.network.socket:getfd()))
client.network.socket:close()
end
return ok
end

@ -19,6 +19,7 @@
--
local lemock = require('lemock')
local lu = require('luaunit')
local utils = require 'ngcp.utils'
local ksrMock = require 'mocks.ksr'
KSR = ksrMock:new()
@ -30,7 +31,10 @@ TestNGCPDlgCnt = {} --class
function TestNGCPDlgCnt:setUp()
mc = lemock.controller()
self.fake_redis = mc:mock()
self.central = mc:mock()
local fake_client = utils.inheritsFrom(mc:mock())
self.socket = mc:mock()
fake_client.network = { socket = self.socket }
self.central = fake_client:create()
self.pair = mc:mock()
package.loaded.redis = self.fake_redis
@ -58,6 +62,8 @@ TestNGCPDlgCnt = {} --class
function TestNGCPDlgCnt:test_connection_fail()
local prev = self.central
self.central:ping() ;mc :error("error")
self.socket:getfd() ;mc:returns(3)
self.socket:close() ;mc:returns(true)
mc:replay()
local res = self.dlg._test_connection(self.central)

@ -21,6 +21,7 @@
local lu = require('luaunit')
local lemock = require('lemock')
local ksrMock = require 'mocks.ksr'
local utils = require 'ngcp.utils'
KSR = ksrMock:new()
@ -32,7 +33,10 @@ TestNGCPRecentCalls = {} --class
function TestNGCPRecentCalls:setUp()
mc = lemock.controller()
self.fake_redis = mc:mock()
self.central = mc:mock()
local fake_client = utils.inheritsFrom(mc:mock())
self.socket = mc:mock()
fake_client.network = { socket = self.socket }
self.central = fake_client:create()
package.loaded.redis = self.fake_redis
local NGCPRecentCalls = require 'ngcp.recentcalls'
@ -58,6 +62,8 @@ TestNGCPRecentCalls = {} --class
function TestNGCPRecentCalls:test_connection_fail()
local prev = self.central
self.central:ping() ;mc :error("error")
self.socket:getfd() ;mc:returns(3)
self.socket:close() ;mc:returns(true)
mc:replay()
local res = self.rcalls._test_connection(self.central)

Loading…
Cancel
Save