Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[action] [PR:266] [link prober] print out error code message when sendHeartbeat fails (#266) #271

Merged
merged 1 commit into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading