Skip to content

Commit

Permalink
fix clear and new test
Browse files Browse the repository at this point in the history
Signed-off-by: dentiny <[email protected]>
  • Loading branch information
dentiny committed Feb 10, 2025
1 parent 0d5ad28 commit 4b96c9b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ray/util/spdlog_newliner_sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class spdlog_newliner_sink final : public spdlog::sinks::base_sink<Mutex> {
if (!buffer_.empty()) {
spdlog::details::log_msg new_log_msg;
new_log_msg.payload = std::string_view{buffer_.data(), buffer_.length()};
buffer_.clear();
internal_sink_->log(std::move(new_log_msg));
buffer_.clear();
}
internal_sink_->flush();
}
Expand Down
13 changes: 13 additions & 0 deletions src/ray/util/tests/spdlog_newliner_sink_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ std::shared_ptr<spdlog::logger> CreateLogger() {
return logger;
}

// Testing senario: Keep writing to spdlog after flush, and check whether all written
// content is correctly reflected.
TEST(NewlinerSinkTest, WriteAfterFlush) {
auto logger = CreateLogger();
constexpr std::string_view kContent = "hello";

testing::internal::CaptureStdout();
logger->log(spdlog::level::info, kContent);
logger->flush();
const std::string stdout_content = testing::internal::GetCapturedStdout();
EXPECT_EQ(stdout_content, kContent);
}

TEST(NewlinerSinkTest, AppendAndFlushTest) {
// Case-1: string with newliner at the end.
{
Expand Down

0 comments on commit 4b96c9b

Please sign in to comment.