Skip to content

Commit 4071924

Browse files
qiluo-msftSviatoslav Boichuk
authored and
Sviatoslav Boichuk
committed
Revert "Fix the issue of ignoring callback calls for removed keys. (sonic-net#789)" (sonic-net#804)
This reverts commit e0f394c. The reason is unexpected behavior change of `get_entry`. ref: sonic-net#789 (comment)
1 parent 76de1c2 commit 4071924

File tree

2 files changed

+12
-35
lines changed

2 files changed

+12
-35
lines changed

common/configdb.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class ConfigDBConnector_Native : public SonicV2Connector_Native
120120
## Dynamic typed functions used in python
121121
@staticmethod
122122
def raw_to_typed(raw_data):
123-
if not raw_data or not raw_data.keys():
123+
if raw_data is None:
124124
return None
125125
typed_data = {}
126126
for raw_key in raw_data:

tests/test_redis_ut.py

+11-34
Original file line numberDiff line numberDiff line change
@@ -634,40 +634,29 @@ def thread_coming_entry():
634634
def test_ConfigDBInit():
635635
table_name_1 = 'TEST_TABLE_1'
636636
table_name_2 = 'TEST_TABLE_2'
637-
table_name_3 = 'TEST_TABLE_3'
638637
test_key = 'key1'
639638
test_data = {'field1': 'value1'}
640-
641-
queue = multiprocessing.Queue()
639+
test_data_update = {'field1': 'value2'}
642640

643641
manager = multiprocessing.Manager()
644642
ret_data = manager.dict()
645643

646-
def test_handler(table, key, data, ret, q=None):
647-
if data is None:
648-
ret[table] = {k: v for k, v in ret[table].items() if k != key}
649-
else:
650-
ret[table] = {key: data}
651-
652-
if q:
653-
q.put(ret[table])
644+
def test_handler(table, key, data, ret):
645+
ret[table] = {key: data}
654646

655-
def test_init_handler(data, ret, queue):
647+
def test_init_handler(data, ret):
656648
ret.update(data)
657-
queue.put(ret)
658649

659-
def thread_listen(ret, queue):
650+
def thread_listen(ret):
660651
config_db = ConfigDBConnector()
661652
config_db.connect(wait_for_init=False)
662653

663654
config_db.subscribe(table_name_1, lambda table, key, data: test_handler(table, key, data, ret),
664655
fire_init_data=False)
665656
config_db.subscribe(table_name_2, lambda table, key, data: test_handler(table, key, data, ret),
666657
fire_init_data=True)
667-
config_db.subscribe(table_name_3, lambda table, key, data: test_handler(table, key, data, ret, queue),
668-
fire_init_data=False)
669658

670-
config_db.listen(init_data_handler=lambda data: test_init_handler(data, ret, queue))
659+
config_db.listen(init_data_handler=lambda data: test_init_handler(data, ret))
671660

672661
config_db = ConfigDBConnector()
673662
config_db.connect(wait_for_init=False)
@@ -677,27 +666,15 @@ def thread_listen(ret, queue):
677666
# Init table data
678667
config_db.set_entry(table_name_1, test_key, test_data)
679668
config_db.set_entry(table_name_2, test_key, test_data)
680-
config_db.set_entry(table_name_3, test_key, {})
681669

682-
thread = multiprocessing.Process(target=thread_listen, args=(ret_data, queue))
670+
thread = multiprocessing.Process(target=thread_listen, args=(ret_data,))
683671
thread.start()
684-
685-
init_data = queue.get(5)
686-
687-
# Verify that all tables initialized correctly
688-
assert init_data[table_name_1] == {test_key: test_data}
689-
assert init_data[table_name_2] == {test_key: test_data}
690-
assert init_data[table_name_3] == {test_key: {}}
691-
692-
# Remove the entry (with no attributes) from the table.
693-
# Verify that the update is received and a callback is called
694-
config_db.set_entry(table_name_3, test_key, None)
695-
696-
table_3_data = queue.get(5)
697-
assert test_key not in table_3_data
698-
672+
time.sleep(5)
699673
thread.terminate()
700674

675+
assert ret_data[table_name_1] == {test_key: test_data}
676+
assert ret_data[table_name_2] == {test_key: test_data}
677+
701678

702679
def test_DBConnectFailure():
703680
""" Verify that a DB connection failure will not cause a process abort

0 commit comments

Comments
 (0)