MT#16773 dlgcnt: don't allow negative counters by default

- controled by allow_negative config
- add unit test for zero, and negative decr

Change-Id: I2396f1640759f1b9741f0e40ce9505306bd3d27d
(cherry picked from commit 15163bb6b3)
changes/18/3618/1
Victor Seva 10 years ago
parent fab902f35c
commit 2995aa207f

@ -53,7 +53,8 @@ end
port = 6379,
db = "4"
},
check_pair_dup = false
check_pair_dup = false,
allow_negative = false
},
central = {},
pair = {}
@ -80,6 +81,9 @@ end
if res == 0 then
self.central:del(key);
sr.log("dbg", string.format("central:del[%s] counter is 0\n", key));
elseif res < 0 and not self.config.allow_negative then
self.central:del(key);
sr.log("warn", string.format("central:del[%s] counter was %s\n", key, tostring(res)));
else
sr.log("dbg", string.format("central:decr[%s]=>[%s]\n", key, tostring(res)));
end

@ -132,6 +132,61 @@ TestNGCPDlgCnt = {} --class
assertIs(self.dlg.pair, self.pair)
end
function TestNGCPDlgCnt:test_del_zero()
local c = self.dlg.config
self.pair:ping() ;mc :returns(true)
self.pair:lpop("callid0") ;mc :returns("total")
self.pair:lpop("callid0") ;mc :returns(nil)
self.central:del("total") ;mc :returns(true)
self.central:ping() ;mc :returns(true)
self.central:decr("total") ;mc :returns(0)
mc:replay()
self.dlg:del("callid0")
mc:verify()
assertIs(self.dlg.central, self.central)
assertIs(self.dlg.pair, self.pair)
end
function TestNGCPDlgCnt:test_del_negative()
local c = self.dlg.config
c.allow_negative = false
self.pair:ping() ;mc :returns(true)
self.pair:lpop("callid0") ;mc :returns("total")
self.pair:lpop("callid0") ;mc :returns(nil)
self.central:ping() ;mc :returns(true)
self.central:decr("total") ;mc :returns(-1)
self.central:del("total") ;mc :returns(true)
mc:replay()
self.dlg:del("callid0")
mc:verify()
assertIs(self.dlg.central, self.central)
assertIs(self.dlg.pair, self.pair)
end
function TestNGCPDlgCnt:test_del_negative_ok()
local c = self.dlg.config
c.allow_negative = true
self.pair:ping() ;mc :returns(true)
self.pair:lpop("callid0") ;mc :returns("total")
self.pair:lpop("callid0") ;mc :returns(nil)
self.central:ping() ;mc :returns(true)
self.central:decr("total") ;mc :returns(-1)
mc:replay()
self.dlg:del("callid0")
mc:verify()
assertIs(self.dlg.central, self.central)
assertIs(self.dlg.pair, self.pair)
end
function TestNGCPDlgCnt:test_del_multy()
local c = self.dlg.config
self.pair:ping() ;mc :returns(true)

Loading…
Cancel
Save