diff --git a/common/configdb.cpp b/common/configdb.cpp index 6d8747bf..c6939b91 100644 --- a/common/configdb.cpp +++ b/common/configdb.cpp @@ -24,7 +24,7 @@ void ConfigDBConnector_Native::db_connect(string db_name, bool wait_for_init, bo if (wait_for_init) { auto& client = get_redis_client(m_db_name); - auto pubsub = client.pubsub(); + auto pubsub = make_shared(&client); auto initialized = client.get(INIT_INDICATOR); if (!initialized || initialized->empty()) { diff --git a/common/dbconnector.h b/common/dbconnector.h index bdd410f5..5ec2877c 100644 --- a/common/dbconnector.h +++ b/common/dbconnector.h @@ -172,6 +172,9 @@ class DBConnector : public RedisContext /* Create new context to DB */ DBConnector *newConnector(unsigned int timeout) const; +#ifndef SWIG + __attribute__((deprecated)) +#endif PubSub *pubsub(); int64_t del(const std::string &key); diff --git a/tests/test_redis_ut.py b/tests/test_redis_ut.py index 58b0b48e..0fc54acf 100644 --- a/tests/test_redis_ut.py +++ b/tests/test_redis_ut.py @@ -381,6 +381,7 @@ def test_ConfigDBConnector(): def test_ConfigDBConnectorSeparator(): db = swsscommon.DBConnector("APPL_DB", 0, True) config_db = ConfigDBConnector() + # set wait for init to True to cover wait_for_init code. config_db.db_connect("APPL_DB", False, False) config_db.get_redis_client(config_db.APPL_DB).flushdb() config_db.set_entry("TEST_PORT", "Ethernet222", {"alias": "etp2x"}) @@ -677,3 +678,17 @@ def test_DBConnectFailure(): with pytest.raises(RuntimeError): db = swsscommon.DBConnector(0, nonexisting_host, 0) +def test_ConfigDBWaitInit(): + config_db = ConfigDBConnector() + config_db.connect(wait_for_init=False) + client = config_db.get_redis_client(config_db.CONFIG_DB) + suc = client.set(config_db.INIT_INDICATOR, 1) + assert suc + + # set wait for init to True to cover wait_for_init code. + config_db = ConfigDBConnector() + config_db.db_connect(config_db.CONFIG_DB, True, False) + + config_db.set_entry("TEST_PORT", "Ethernet111", {"alias": "etp1x"}) + allconfig = config_db.get_config() + assert allconfig["TEST_PORT"]["Ethernet111"]["alias"] == "etp1x"