Skip to content

Commit

Permalink
Add more debug info for gtest failure (#4769)
Browse files Browse the repository at this point in the history
Signed-off-by: yibin <[email protected]>
  • Loading branch information
yibin87 authored Apr 27, 2022
1 parent 0e1a373 commit c6740e5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 10 additions & 1 deletion dbms/src/Flash/Mpp/MPPTunnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,25 @@ MPPTunnelBase<Writer>::~MPPTunnelBase()
{
std::unique_lock lock(mu);
if (finished)
{
LOG_FMT_TRACE(log, "already finished!");
return;
}

/// make sure to finish the tunnel after it is connected
waitUntilConnectedOrFinished(lock);
finishSendQueue();
}
LOG_FMT_TRACE(log, "waiting consumer finish!");
waitForConsumerFinish(/*allow_throw=*/false);
}
catch (...)
{
tryLogCurrentException(log, "Error in destructor function of MPPTunnel");
}
LOG_FMT_TRACE(log, "waiting child thread finished!");
thread_manager->wait();
LOG_FMT_TRACE(log, "destructed tunnel obj!");
}

template <typename Writer>
Expand Down Expand Up @@ -296,9 +303,11 @@ void MPPTunnelBase<Writer>::waitForConsumerFinish(bool allow_throw)
assert(connected);
}
#endif
LOG_FMT_TRACE(log, "start wait for consumer finish!");
String err_msg = consumer_state.getError(); // may blocking
if (allow_throw && !err_msg.empty())
throw Exception("Consumer exits unexpected, " + err_msg);
LOG_FMT_TRACE(log, "end wait for consumer finish!");
}

template <typename Writer>
Expand Down Expand Up @@ -330,8 +339,8 @@ template <typename Writer>
void MPPTunnelBase<Writer>::consumerFinish(const String & err_msg, bool need_lock)
{
// must finish send_queue outside of the critical area to avoid deadlock with write.
LOG_FMT_TRACE(log, "calling consumer Finish");
send_queue.finish();

auto rest_work = [this, &err_msg] {
// it's safe to call it multiple times
if (finished && consumer_state.errHasSet())
Expand Down
7 changes: 7 additions & 0 deletions dbms/src/Flash/Mpp/tests/gtest_mpptunnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class MPPTunnelTest : public MPPTunnelBase<PacketWriter>
{
return thread_manager;
}
LoggerPtr getLog()
{
return log;
}
};

using MPPTunnelTestPtr = std::shared_ptr<MPPTunnelTest>;
Expand Down Expand Up @@ -94,7 +98,9 @@ struct MockLocalReader
if (tunnel)
{
// In case that ExchangeReceiver throw error before finish reading from mpp_tunnel
LOG_FMT_TRACE(tunnel->getLog(), "before mocklocalreader invoking consumerFinish!");
tunnel->consumerFinish("Receiver closed");
LOG_FMT_TRACE(tunnel->getLog(), "after mocklocalreader invoking consumerFinish!");
}
}

Expand Down Expand Up @@ -483,6 +489,7 @@ try
GTEST_ASSERT_EQ(mpp_tunnel_ptr->getFinishFlag(), true);
GTEST_ASSERT_EQ(local_reader_ptr->write_packet_vec.size(), 1);
GTEST_ASSERT_EQ(local_reader_ptr->write_packet_vec[0], "First");
LOG_FMT_TRACE(mpp_tunnel_ptr->getLog(), "basic logic done!");
}
CATCH

Expand Down

0 comments on commit c6740e5

Please sign in to comment.