Skip to content

Commit

Permalink
add test case with queue reallocation
Browse files Browse the repository at this point in the history
  • Loading branch information
odygrd committed Nov 11, 2024
1 parent a847160 commit 7d6a2e7
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions test/integration_tests/MultiFrontendThreadsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,35 @@

using namespace quill;

/**
* Create a custom frontend config
*/
struct CustomFrontendOptions
{
static constexpr quill::QueueType queue_type = quill::QueueType::UnboundedBlocking;
static constexpr uint32_t initial_queue_capacity = 32;

static constexpr uint32_t blocking_queue_retry_interval_ns = 800;
static constexpr bool huge_pages_enabled = false;
};

/**
* A new CustomFrontend and CustomLogger should be defined to use the custom frontend options.
*/
using CustomFrontend = quill::FrontendImpl<CustomFrontendOptions>;
using CustomLogger = quill::LoggerImpl<CustomFrontendOptions>;

/***/
TEST_CASE("multi_frontend_threads")
TEST_CASE("multi_frontend_threads_with_queue_reallocation")
{
static constexpr size_t number_of_messages = 1000;
static constexpr size_t number_of_messages = 5000;
static constexpr size_t number_of_threads = 10;
static constexpr char const* filename = "multi_frontend_threads.log";
static constexpr char const* filename = "multi_frontend_threads_with_queue_reallocation.log";
static std::string const logger_name_prefix = "logger_";

// Start the logging backend thread
BackendOptions bo;
bo.sleep_duration = std::chrono::seconds {1};
Backend::start();

std::vector<std::thread> threads;
Expand All @@ -31,10 +51,10 @@ TEST_CASE("multi_frontend_threads")
threads.emplace_back(
[i]() mutable
{
Frontend::preallocate();
CustomFrontend::preallocate();

// Set writing logging to a file
auto file_sink = Frontend::create_or_get_sink<FileSink>(
auto file_sink = CustomFrontend::create_or_get_sink<FileSink>(
filename,
[]()
{
Expand All @@ -44,7 +64,7 @@ TEST_CASE("multi_frontend_threads")
}(),
FileEventNotifier{});

Logger* logger = Frontend::create_or_get_logger(
CustomLogger* logger = CustomFrontend::create_or_get_logger(
logger_name_prefix + std::to_string(i), std::move(file_sink),
quill::PatternFormatterOptions{
"%(time) [%(thread_id)] %(short_source_location:<28) LOG_%(log_level:<9) %(logger:<12) "
Expand All @@ -64,11 +84,13 @@ TEST_CASE("multi_frontend_threads")
elem.join();
}

Backend::notify();

// flush all log and remove all loggers
for (Logger* logger : Frontend::get_all_loggers())
for (CustomLogger* logger : CustomFrontend::get_all_loggers())
{
logger->flush_log();
Frontend::remove_logger(logger);
CustomFrontend::remove_logger(logger);
}

// Wait until the backend thread stops for test stability
Expand Down

0 comments on commit 7d6a2e7

Please sign in to comment.