Skip to content

Commit b88c275

Browse files
committed
uplift code diff coverage
1 parent 1496093 commit b88c275

7 files changed

+47
-21
lines changed

src/DbInterface.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ void DbInterface::setMuxMode(const std::string &portName, const std::string stat
12311231
//
12321232
// handle set mux mode
12331233
//
1234-
void DbInterface::handleSetMuxMode(const std::string portName, const std::string state)
1234+
void DbInterface::handleSetMuxMode(const std::string &portName, const std::string state)
12351235
{
12361236
MUXLOGWARNING(boost::format("%s: configuring mux mode to %s after warm restart") % portName % state);
12371237

src/DbInterface.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ class DbInterface
271271
*
272272
* @return none
273273
*/
274-
virtual void setMuxMode(const std::string &portName, const std::string state);
274+
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-
virtual void setMuxReconciled();
283+
void setMuxReconciled();
284284

285285
/**
286286
* @method checkWarmRestart
@@ -414,7 +414,7 @@ class DbInterface
414414
*
415415
* @return none
416416
*/
417-
void handleSetMuxReconciled();
417+
virtual void handleSetMuxReconciled();
418418

419419
/**
420420
* @method handleSetMuxMode
@@ -426,7 +426,7 @@ class DbInterface
426426
*
427427
* @return none
428428
*/
429-
void handleSetMuxMode(const std::string portName, const std::string state);
429+
virtual void handleSetMuxMode(const std::string &portName, const std::string state);
430430

431431
/**
432432
*@method processTorMacAddress

test/FakeDbInterface.cpp

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

95-
void FakeDbInterface::setMuxReconciled()
95+
void FakeDbInterface::handleSetMuxReconciled()
9696
{
9797
mSetMuxReconciledInvokeCount += 1;
9898
}
9999

100-
void FakeDbInterface::checkWarmRestart(const std::string &portName)
100+
void FakeDbInterface::handleSetMuxMode(const std::string &portName, const std::string state)
101101
{
102-
mCheckWarmRestartInvokeCount += 1;
102+
mSetMuxModeInvokeCount += 1;
103103
}
104104

105105
} /* namespace test */

test/FakeDbInterface.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ 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;
65+
private:
66+
virtual void handleSetMuxMode(const std::string &portName, const std::string state) override;
67+
virtual void handleSetMuxReconciled() override;
6768

6869
public:
6970
mux_state::MuxState::Label mNextMuxState;
@@ -84,7 +85,7 @@ class FakeDbInterface: public mux::DbInterface
8485
uint64_t mExpectedPacketCount = 0;
8586

8687
uint32_t mSetMuxReconciledInvokeCount = 0;
87-
uint32_t mCheckWarmRestartInvokeCount = 0;
88+
uint32_t mSetMuxModeInvokeCount = 0;
8889
};
8990

9091
} /* namespace test */

test/LinkManagerStateMachineTest.cpp

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

194193
void LinkManagerStateMachineTest::setMuxActive()
@@ -1165,11 +1164,4 @@ TEST_F(LinkManagerStateMachineTest, EnableDecreaseLinkProberIntervalFeature)
11651164
EXPECT_EQ(mFakeMuxPort.mFakeLinkProber->mDecreaseIntervalCallCount, 1);
11661165
}
11671166

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

test/MuxManagerTest.cpp

+33-2
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,19 @@ void MuxManagerTest::processWarmRestartFlag(const std::string &flag)
205205
mMuxManagerPtr->processWarmRestartFlag(flag);
206206
}
207207

208+
void MuxManagerTest::checkWarmRestart(const std::string &portName)
209+
{
210+
std::shared_ptr<mux::MuxPort> muxPortPtr = mMuxManagerPtr->mPortMap[portName];
211+
212+
muxPortPtr->checkWarmRestart();
213+
}
214+
215+
void MuxManagerTest::updatePortReconciliationCount(int increment)
216+
{
217+
mMuxManagerPtr->updateWarmRestartReconciliationCount(increment);
218+
runIoService(1);
219+
}
220+
208221
void MuxManagerTest::initLinkProberActiveActive(std::shared_ptr<link_manager::ActiveActiveStateMachine> linkManagerStateMachineActiveActive)
209222
{
210223
mFakeLinkProber = std::make_shared<FakeLinkProber> (linkManagerStateMachineActiveActive->getLinkProberStateMachinePtr().get());
@@ -646,9 +659,27 @@ TEST_F(MuxManagerTest, WarmRestart)
646659
std::string flag = "true";
647660
processWarmRestartFlag(flag);
648661
EXPECT_TRUE(mMuxManagerPtr->getWarmRestartFlag());
662+
663+
updatePortReconciliationCount(1);
664+
checkWarmRestart(port);
649665

650-
EXPECT_EQ(mDbInterfacePtr->mSetMuxReconciledInvokeCount, 0);
651-
runIoService();
666+
runIoService(4);
667+
EXPECT_EQ(mDbInterfacePtr->mSetMuxModeInvokeCount, 1);
668+
EXPECT_EQ(mDbInterfacePtr->mSetMuxReconciledInvokeCount, 1);
669+
}
670+
671+
TEST_F(MuxManagerTest, WarmRestartReconciliationTimeout)
672+
{
673+
std::string port = "Ethernet0";
674+
675+
createPort(port);
676+
EXPECT_FALSE(mMuxManagerPtr->getWarmRestartFlag());
677+
678+
std::string flag = "true";
679+
processWarmRestartFlag(flag);
680+
EXPECT_TRUE(mMuxManagerPtr->getWarmRestartFlag());
681+
682+
runIoService(2);
652683
EXPECT_EQ(mDbInterfacePtr->mSetMuxReconciledInvokeCount, 1);
653684
}
654685

test/MuxManagerTest.h

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class MuxManagerTest: public testing::Test
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);
7878
void processWarmRestartFlag(const std::string &flag);
79+
void checkWarmRestart(const std::string &portName);
80+
void updatePortReconciliationCount(int increment);
7981
void createPort(std::string port, common::MuxPortConfig::PortCableType portCableType = common::MuxPortConfig::PortCableType::ActiveStandby);
8082

8183
public:

0 commit comments

Comments
 (0)