Skip to content

Commit 57eea2b

Browse files
committed
test_SubscriberStateTable: add test for final state convergence
1 parent f8452f6 commit 57eea2b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/test_redis_ut.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ def test_SubscriberStateTable():
8484
sel = swsscommon.Select()
8585
cst = swsscommon.SubscriberStateTable(db, "testsst")
8686
sel.addSelectable(cst)
87+
88+
# Set one field and pop
8789
fvs = swsscommon.FieldValuePairs([('a','b')])
8890
t.set("aaa", fvs)
8991
(state, c) = sel.select()
@@ -94,6 +96,34 @@ def test_SubscriberStateTable():
9496
assert len(cfvs) == 1
9597
assert cfvs[0] == ('a', 'b')
9698

99+
# Set one field twice and then pop twice. First pop should return the final field/values, second pop should return the same final field/values
100+
fvs = swsscommon.FieldValuePairs([('c','b0')])
101+
t.set("aaa", fvs)
102+
fvs = swsscommon.FieldValuePairs([('c','b1')])
103+
t.set("aaa", fvs)
104+
(state, c) = sel.select()
105+
assert state == swsscommon.Select.OBJECT
106+
(key, op, cfvs) = cst.pop()
107+
assert key == "aaa"
108+
assert op == "SET"
109+
for fv in cfvs:
110+
if fv[0] == 'c':
111+
assert fv[1] == 'b1'
112+
break
113+
else:
114+
assert False, "Field 'c' not found in the final field/values"
115+
(key, op, cfvs) = cst.pop()
116+
assert key == "aaa"
117+
assert op == "SET"
118+
for fv in cfvs:
119+
print(fv)
120+
if fv[0] == 'c':
121+
assert fv[1] == 'b1'
122+
break
123+
else:
124+
assert False, "Field 'c' not found in the final field/values"
125+
126+
97127
def test_SubscriberEventTable():
98128
db = swsscommon.DBConnector("CONFIG_DB", 0, True)
99129
db.flushdb()

0 commit comments

Comments
 (0)