Skip to content

Commit

Permalink
Sergei comments
Browse files Browse the repository at this point in the history
  • Loading branch information
maksimdrachov committed Dec 4, 2024
1 parent 6bcb164 commit 0bd1a33
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion include/olga_scheduler/olga_scheduler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Event : private cavl::Node<Event<TimePoint>>
}

/// Diagnostic accessor for testing. Not intended for normal use.
/// Empty option means that the event is not scheduled or canceled.
/// The deadline is TimePoint::min() if the event is not scheduled or canceled.
/// It is guaranteed that while an event resides in the tree, it has a valid deadline set.
[[nodiscard]] TimePoint getDeadline() const noexcept { return deadline_; }

Expand Down
17 changes: 7 additions & 10 deletions tests/test_olga_scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace
{

/// Expected type ID for the type returned from repeat(), poll() and defer().
constexpr std::array<std::uint8_t, 16> expected_type_id =
constexpr std::array<std::uint8_t, 16> event_type_id =
{0xB6, 0x87, 0x48, 0xA6, 0x7A, 0xDB, 0x4D, 0xF1, 0xB3, 0x1D, 0xA9, 0x8D, 0x50, 0xA7, 0x82, 0x47};

/// This clock has to keep global state to implement the TrivialClock trait.
Expand Down Expand Up @@ -109,8 +109,7 @@ TEST(TestOlgaScheduler, EventLoopBasic)
EXPECT_FALSE(evl.isEmpty());

// Check the type ID of return type repeat().
const auto actual_type_id = decltype(evt_a)::_get_type_id_();
EXPECT_THAT(actual_type_id, ElementsAreArray(expected_type_id));
EXPECT_THAT(decltype(evt_a)::_get_type_id_(), ElementsAreArray(event_type_id));

auto evt_b = evl.repeat(100ms, // Smaller deadline goes on the left.
[&](const auto& arg) { b.emplace(arg); });
Expand Down Expand Up @@ -188,15 +187,15 @@ TEST(TestOlgaScheduler, EventLoopBasic)
c.reset();
d.reset();
// Ensure the deadline is cleared on those events that are canceled.
EXPECT_TRUE(evt_a.getDeadline() > Loop::time_point::min());
EXPECT_TRUE(evt_b.getDeadline() > Loop::time_point::min());
EXPECT_THAT(evt_a.getDeadline(), Gt(Loop::time_point::min()));
EXPECT_THAT(evt_b.getDeadline(), Gt(Loop::time_point::min()));
EXPECT_THAT(evt_c.getDeadline(), Loop::time_point::min());
EXPECT_THAT(evt_d.getDeadline(), Loop::time_point::min());

// Drop the second event and ensure it is removed from the tree immediately.
SteadyClockMock::advance(1050ms);
EXPECT_THAT(SteadyClockMock::now().time_since_epoch(), 13'050ms);
EXPECT_TRUE(evt_b.getDeadline() > Loop::time_point::min());
EXPECT_THAT(evt_b.getDeadline(), Gt(Loop::time_point::min()));
evt_b.cancel();
EXPECT_THAT(evt_b.getDeadline(), Loop::time_point::min()); // Unregistered, cleared.
EXPECT_THAT(evl.getTree().size(), 1); // Freed already.
Expand Down Expand Up @@ -274,8 +273,7 @@ TEST(TestOlgaScheduler, EventLoopPoll)
EXPECT_THAT(evl.getTree()[0U]->getDeadline().time_since_epoch(), 110ms);

// Check the type ID of return type poll().
const auto actual_type_id = decltype(evt)::_get_type_id_();
EXPECT_THAT(actual_type_id, ElementsAreArray(expected_type_id));
EXPECT_THAT(decltype(evt)::_get_type_id_(), ElementsAreArray(event_type_id));

SteadyClockMock::advance(30ms);
EXPECT_THAT(SteadyClockMock::now().time_since_epoch(), 130ms);
Expand Down Expand Up @@ -304,8 +302,7 @@ TEST(TestOlgaScheduler, EventLoopDefer_single_overdue)
auto evt = evl.defer(SteadyClockMock::now() + 1000ms, [](const auto&) {});

// Check the type ID of return type defer().
const auto actual_type_id = decltype(evt)::_get_type_id_();
EXPECT_THAT(actual_type_id, ElementsAreArray(expected_type_id));
EXPECT_THAT(decltype(evt)::_get_type_id_(), ElementsAreArray(event_type_id));

// This is special case - only one deferred event (and no "repeat"-s!), and it is already overdue (by +30ms).
// So, `next_deadline` should be `time_point::max()` b/c there will be nothing left pending after spin.
Expand Down

0 comments on commit 0bd1a33

Please sign in to comment.