Skip to content

Commit 1496093

Browse files
committed
add unit tests
1 parent a15cc21 commit 1496093

10 files changed

+54
-7
lines changed

src/DbInterface.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,7 @@ void DbInterface::getWarmRestartFlag(std::shared_ptr<swss::DBConnector> stateDbC
11691169
//
11701170
// check if warm restart is on when port completes reconciliation
11711171
//
1172-
void DbInterface::checkWarmRestart(const std::string portName)
1172+
void DbInterface::checkWarmRestart(const std::string &portName)
11731173
{
11741174
MUXLOGDEBUG(portName);
11751175

@@ -1213,7 +1213,7 @@ void DbInterface::handleSetMuxReconciled()
12131213
//
12141214
// set config db mux mode
12151215
//
1216-
void DbInterface::setMuxMode(const std::string portName, const std::string state)
1216+
void DbInterface::setMuxMode(const std::string &portName, const std::string state)
12171217
{
12181218
MUXLOGDEBUG(portName);
12191219

src/DbInterface.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class DbInterface
271271
*
272272
* @return none
273273
*/
274-
void setMuxMode(const std::string portName, const std::string state);
274+
virtual void setMuxMode(const std::string &portName, const std::string state);
275275

276276
/**
277277
* @method setMuxReconciled
@@ -280,7 +280,7 @@ class DbInterface
280280
*
281281
* @return none
282282
*/
283-
void setMuxReconciled();
283+
virtual void setMuxReconciled();
284284

285285
/**
286286
* @method checkWarmRestart
@@ -291,7 +291,7 @@ class DbInterface
291291
*
292292
* @return none
293293
*/
294-
void checkWarmRestart(const std::string portName);
294+
virtual void checkWarmRestart(const std::string &portName);
295295

296296
private:
297297
friend class test::MuxManagerTest;

src/MuxManager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ void MuxManager::generateServerMac(uint16_t serverId, std::array<uint8_t, ETHER_
476476
//
477477
// process warm restart flag
478478
//
479-
void MuxManager::processWarmRestartFlag(const std::string flag)
479+
void MuxManager::processWarmRestartFlag(const std::string &flag)
480480
{
481481
mWarmRestartFlag = flag;
482482

src/MuxManager.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ class MuxManager
394394
*
395395
* @return
396396
*/
397-
void processWarmRestartFlag(const std::string flag);
397+
void processWarmRestartFlag(const std::string &flag);
398398

399399
/**
400400
* @method getWarmRestartFlag

test/FakeDbInterface.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,14 @@ void FakeDbInterface::postPckLossRatio(
9292
mExpectedPacketCount = expectedPacketCount;
9393
}
9494

95+
void FakeDbInterface::setMuxReconciled()
96+
{
97+
mSetMuxReconciledInvokeCount += 1;
98+
}
99+
100+
void FakeDbInterface::checkWarmRestart(const std::string &portName)
101+
{
102+
mCheckWarmRestartInvokeCount += 1;
103+
}
104+
95105
} /* namespace test */

test/FakeDbInterface.h

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class FakeDbInterface: public mux::DbInterface
6262

6363
void setNextMuxState(mux_state::MuxState::Label label) {mNextMuxState = label;};
6464

65+
virtual void setMuxReconciled() override;
66+
virtual void checkWarmRestart(const std::string &portName) override;
6567

6668
public:
6769
mux_state::MuxState::Label mNextMuxState;
@@ -80,6 +82,9 @@ class FakeDbInterface: public mux::DbInterface
8082
uint32_t mPostLinkProberMetricsInvokeCount = 0;
8183
uint64_t mUnknownEventCount = 0;
8284
uint64_t mExpectedPacketCount = 0;
85+
86+
uint32_t mSetMuxReconciledInvokeCount = 0;
87+
uint32_t mCheckWarmRestartInvokeCount = 0;
8388
};
8489

8590
} /* namespace test */

test/LinkManagerStateMachineTest.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ void LinkManagerStateMachineTest::activateStateMachine()
188188
{
189189
mFakeMuxPort.activateStateMachine();
190190
mFakeMuxPort.handleDefaultRouteState("ok");
191+
mFakeMuxPort.checkWarmRestart();
191192
}
192193

193194
void LinkManagerStateMachineTest::setMuxActive()
@@ -1164,4 +1165,11 @@ TEST_F(LinkManagerStateMachineTest, EnableDecreaseLinkProberIntervalFeature)
11641165
EXPECT_EQ(mFakeMuxPort.mFakeLinkProber->mDecreaseIntervalCallCount, 1);
11651166
}
11661167

1168+
TEST_F(LinkManagerStateMachineTest, CheckWarmRestart)
1169+
{
1170+
setMuxActive();
1171+
1172+
EXPECT_EQ(mDbInterfacePtr->mCheckWarmRestartInvokeCount, 1);
1173+
}
1174+
11671175
} /* namespace test */

test/LinkManagerStateMachineTest.h

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class LinkManagerStateMachineTest: public ::testing::Test
5555
void postPeerLinkStateEvent(std::string linkState, uint32_t count = 0);
5656
void postPckLossRatioUpdateEvent(uint64_t unknownCount, uint64_t totalCount);
5757
void postPckLossCountsResetEvent();
58+
void checkWarmRestart();
5859

5960
public:
6061
boost::asio::io_service mIoService;

test/MuxManagerTest.cpp

+22
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@ void MuxManagerTest::updatePortCableType(const std::string &port, const std::str
200200
mMuxManagerPtr->updatePortCableType(port, cableType);
201201
}
202202

203+
void MuxManagerTest::processWarmRestartFlag(const std::string &flag)
204+
{
205+
mMuxManagerPtr->processWarmRestartFlag(flag);
206+
}
207+
203208
void MuxManagerTest::initLinkProberActiveActive(std::shared_ptr<link_manager::ActiveActiveStateMachine> linkManagerStateMachineActiveActive)
204209
{
205210
mFakeLinkProber = std::make_shared<FakeLinkProber> (linkManagerStateMachineActiveActive->getLinkProberStateMachinePtr().get());
@@ -631,4 +636,21 @@ INSTANTIATE_TEST_CASE_P(
631636
)
632637
);
633638

639+
TEST_F(MuxManagerTest, WarmRestart)
640+
{
641+
std::string port = "Ethernet0";
642+
643+
createPort(port);
644+
EXPECT_FALSE(mMuxManagerPtr->getWarmRestartFlag());
645+
646+
std::string flag = "true";
647+
processWarmRestartFlag(flag);
648+
EXPECT_TRUE(mMuxManagerPtr->getWarmRestartFlag());
649+
650+
EXPECT_EQ(mDbInterfacePtr->mSetMuxReconciledInvokeCount, 0);
651+
runIoService();
652+
EXPECT_EQ(mDbInterfacePtr->mSetMuxReconciledInvokeCount, 1);
653+
}
654+
634655
} /* namespace test */
656+

test/MuxManagerTest.h

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class MuxManagerTest: public testing::Test
7575
void initLinkProberActiveActive(std::shared_ptr<link_manager::ActiveActiveStateMachine> linkManagerStateMachine);
7676
void initLinkProberActiveStandby(std::shared_ptr<link_manager::ActiveStandbyStateMachine> linkManagerStateMachine);
7777
void generateServerMac(const std::string &portName, std::array<uint8_t, ETHER_ADDR_LEN> &address);
78+
void processWarmRestartFlag(const std::string &flag);
7879
void createPort(std::string port, common::MuxPortConfig::PortCableType portCableType = common::MuxPortConfig::PortCableType::ActiveStandby);
7980

8081
public:

0 commit comments

Comments
 (0)