Skip to content

Commit

Permalink
[link prober] print out error code message when sendHeartbeat fails (
Browse files Browse the repository at this point in the history
…#266)

Summary:
Fixes # (issue)
Print out error code message when sendHeartbeat fails.

sign-off: Jing Zhang zhangjing@microsoft.com
  • Loading branch information
zjswhhh authored Aug 13, 2024
1 parent 22f55a7 commit 287dbd7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/link_prober/LinkProber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ void LinkProber::sendHeartbeat(bool forceSend)
mStream.write_some(boost::asio::buffer(mTxBuffer.data(), mTxPacketSize), errorCode);

if (errorCode) {
MUXLOGTRACE(mMuxPortConfig.getPortName() + ": Failed to send heartbeat!");
MUXLOGTRACE(mMuxPortConfig.getPortName() + ": Failed to send heartbeat! Error code: " + errorCode.message());
} else {
MUXLOGTRACE(mMuxPortConfig.getPortName() + ": Done sending data");
}
Expand Down Expand Up @@ -458,6 +458,7 @@ void LinkProber::handleRecv(
}
} else {
// Unknown ICMP packet, ignore.
MUXLOGTRACE(mMuxPortConfig.getPortName() + ": Failed to receive heartbeat! Error code: " + errorCode.message());
}
// start another receive to consume as much as possible of backlog packets if any
startRecv();
Expand Down
11 changes: 11 additions & 0 deletions test/LinkProberTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,15 @@ TEST_F(LinkProberTest, InitializeException)
EXPECT_THROW(initialize(), common::SocketErrorException);
}

TEST_F(LinkProberTest, LogErrorCodeMessage)
{
EXPECT_THROW(simulateBadFileDescriptor(), boost::system::system_error);

try {
simulateBadFileDescriptor();
} catch (const boost::system::system_error& e) {
EXPECT_EQ(e.code().value(), boost::system::errc::bad_file_descriptor);
EXPECT_EQ(e.code().message(), "Bad file descriptor");
}
}
} /* namespace test */
4 changes: 4 additions & 0 deletions test/LinkProberTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ class LinkProberTest: public ::testing::Test
void initTxBufferTlvSendProbe() {mLinkProber.initTxBufferTlvSendProbe();}
void initTxBufferSentinel() {mLinkProber.initTxBufferTlvSentinel();}

void simulateBadFileDescriptor() {
throw boost::system::system_error(make_error_code(boost::system::errc::bad_file_descriptor));
}

boost::asio::io_service mIoService;
common::MuxConfig mMuxConfig;
std::shared_ptr<FakeDbInterface> mDbInterfacePtr;
Expand Down

0 comments on commit 287dbd7

Please sign in to comment.