Skip to content

Commit

Permalink
add some unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
odygrd committed Jun 4, 2024
1 parent 6912c84 commit 5872f6d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion quill/test/integration_tests/BoundedDroppingQueueTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ TEST_CASE("bounded_dropping_queue")
LOG_ERROR(logger, "Log something to fulfill the bound queue {}", i);
}

logger->flush_log();
logger->flush_log(0);

// Wait until the backend thread stops for test stability
Backend::stop();
Expand Down
2 changes: 2 additions & 0 deletions quill/test/unit_tests/LoggerManagerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ TEST_CASE("create_get_remove_logger")
REQUIRE_EQ(lm.get_all_loggers().size(), 0);
REQUIRE_EQ(lm.get_number_of_loggers(), 0);
}

REQUIRE_EQ(lm.get_valid_logger(), nullptr);
}

TEST_SUITE_END();
54 changes: 54 additions & 0 deletions quill/test/unit_tests/UnboundedQueueTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,58 @@ TEST_CASE("unbounded_queue_read_write_multithreaded_plain_ints")
REQUIRE(buffer.empty());
}

TEST_CASE("unbounded_queue_max_limit")
{
UnboundedSPSCQueue buffer{1024};

constexpr uint64_t half_gb = 500u * 1024u * 1024u;
constexpr uint64_t two_gb = 2u * 1024u * 1024u * 1024u - 1;
constexpr uint64_t three_gb = 3u * 1024u * 1024u * 1024u;

auto* write_buffer_a = buffer.prepare_write(half_gb, quill::QueueType::UnboundedUnlimited);
REQUIRE(write_buffer_a);
buffer.finish_write(half_gb);
buffer.commit_write();

auto* write_buffer_b = buffer.prepare_write(two_gb, quill::QueueType::UnboundedUnlimited);
REQUIRE(write_buffer_b);
buffer.finish_write(two_gb);
buffer.commit_write();

// Buffer is filled with two GB here, we can try to reserve more to allocate another queue
auto* write_buffer_c = buffer.prepare_write(two_gb, quill::QueueType::UnboundedBlocking);
REQUIRE_FALSE(write_buffer_c);

write_buffer_c = buffer.prepare_write(two_gb, quill::QueueType::UnboundedDropping);
REQUIRE_FALSE(write_buffer_c);

// Buffer is filled with two GB here, we can try to reserve more to allocate another queue
// for the UnboundedLimit queue
write_buffer_c = buffer.prepare_write(two_gb, quill::QueueType::UnboundedUnlimited);
REQUIRE(write_buffer_c);
buffer.finish_write(two_gb);
buffer.commit_write();

// Try to allocate over 2GB
REQUIRE_THROWS_AS(QUILL_MAYBE_UNUSED auto* write_buffer_z =
buffer.prepare_write(three_gb, quill::QueueType::UnboundedUnlimited),
quill::QuillError);

auto read_result_a = buffer.prepare_read();
REQUIRE(read_result_a.read_pos);
buffer.finish_read(half_gb);
buffer.commit_read();

auto read_result_b = buffer.prepare_read();
REQUIRE(read_result_b.read_pos);
buffer.finish_read(two_gb);
buffer.commit_read();

auto read_result_c = buffer.prepare_read();
REQUIRE(read_result_c.read_pos);
buffer.finish_read(two_gb);
buffer.commit_read();

REQUIRE(buffer.empty());
}
TEST_SUITE_END();

0 comments on commit 5872f6d

Please sign in to comment.