diff --git a/tests/mock_tests/Makefile.am b/tests/mock_tests/Makefile.am index bf6b6a83c32..e4a7c9355b8 100644 --- a/tests/mock_tests/Makefile.am +++ b/tests/mock_tests/Makefile.am @@ -54,6 +54,8 @@ tests_SOURCES = aclorch_ut.cpp \ mux_rollback_ut.cpp \ warmrestartassist_ut.cpp \ test_failure_handling.cpp \ + warmrestarthelper_ut.cpp \ + $(top_srcdir)/warmrestart/warmRestartHelper.cpp \ $(top_srcdir)/lib/gearboxutils.cpp \ $(top_srcdir)/lib/subintf.cpp \ $(top_srcdir)/orchagent/orchdaemon.cpp \ diff --git a/tests/mock_tests/warmrestarthelper_ut.cpp b/tests/mock_tests/warmrestarthelper_ut.cpp new file mode 100644 index 00000000000..81e177065c8 --- /dev/null +++ b/tests/mock_tests/warmrestarthelper_ut.cpp @@ -0,0 +1,86 @@ +#include "warmRestartHelper.h" +#include "warm_restart.h" +#include "mock_table.h" +#include "ut_helper.h" + +using namespace testing_db; + +namespace wrhelper_test +{ + struct WRHelperTest : public ::testing::Test + { + std::shared_ptr m_app_db; + std::shared_ptr m_pipeline; + std::shared_ptr m_routeTable; + std::shared_ptr m_routeProducerTable; + std::shared_ptr wrHelper; + + void SetUp() override + { + m_app_db = std::make_shared("APPL_DB", 0); + m_pipeline = std::make_shared(m_app_db.get()); + m_routeTable = std::make_shared(m_app_db.get(), "ROUTE_TABLE"); + m_routeProducerTable = std::make_shared(m_app_db.get(), "ROUTE_TABLE"); + wrHelper = std::make_shared(m_pipeline.get(), m_routeProducerTable.get(), "ROUTE_TABLE", "bgp", "bgp"); + testing_db::reset(); + } + + void TearDown() override { + } + }; + + TEST_F(WRHelperTest, testReconciliation) + { + /* Initialize WR */ + wrHelper->setState(WarmStart::INITIALIZED); + ASSERT_EQ(wrHelper->getState(), WarmStart::INITIALIZED); + + /* Old-life entries */ + m_routeTable->set("1.0.0.0/24", + { + {"ifname", "eth1"}, + {"nexthop", "2.0.0.0"} + }); + m_routeTable->set("1.1.0.0/24", + { + {"ifname", "eth2"}, + {"nexthop", "2.1.0.0"}, + {"weight", "1"}, + }); + wrHelper->runRestoration(); + ASSERT_EQ(wrHelper->getState(), WarmStart::RESTORED); + + /* Insert new life entries */ + wrHelper->insertRefreshMap({ + "1.0.0.0/24", + "SET", + { + {"ifname", "eth1"}, + {"nexthop", "2.0.0.0"}, + {"protocol", "kernel"} + } + }); + wrHelper->insertRefreshMap({ + "1.1.0.0/24", + "SET", + { + {"ifname", "eth2"}, + {"nexthop", "2.1.0.0,2.5.0.0"}, + {"weight", "4"}, + {"protocol", "kernel"} + } + }); + wrHelper->reconcile(); + ASSERT_EQ(wrHelper->getState(), WarmStart::RECONCILED); + + std::string val; + ASSERT_TRUE(m_routeTable->hget("1.0.0.0/24", "protocol", val)); + ASSERT_EQ(val, "kernel"); + + m_routeTable->hget("1.1.0.0/24", "protocol", val); + ASSERT_EQ(val, "kernel"); + + m_routeTable->hget("1.1.0.0/24", "weight", val); + ASSERT_EQ(val, "4"); + } +}