Skip to content

Commit

Permalink
Add unit test for optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinTF committed Mar 13, 2024
1 parent b003651 commit 365469e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/util/CancellationHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ class CancellationHandle {
FRIEND_TEST(CancellationHandle, verifyIsCancelledDoesPleaseWatchDog);
FRIEND_TEST(CancellationHandle,
verifyPleaseWatchDogDoesNotAcceptInvalidState);
FRIEND_TEST(CancellationHandle, verifyWatchDogEndsEarlyIfCancelled);
};

using SharedCancellationHandle = std::shared_ptr<CancellationHandle<>>;
Expand Down
18 changes: 18 additions & 0 deletions test/CancellationHandleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,24 @@ TEST(CancellationHandle, verifyIsCancelledDoesPleaseWatchDog) {

// _____________________________________________________________________________

TEST(CancellationHandle, verifyWatchDogEndsEarlyIfCancelled) {
CancellationHandle<ENABLED> handle;
handle.cancel(MANUAL);

handle.startWatchDog();
// Wait for Watchdog to start
std::this_thread::sleep_for(1ms);

handle.cancellationState_ = WAITING_FOR_CHECK;

// Wait for one watchdog cycle + tolerance
std::this_thread::sleep_for(DESIRED_CANCELLATION_CHECK_INTERVAL + 1ms);
// If the watchdog were running it would've set this to CHECK_WINDOW_MISSED
EXPECT_EQ(handle.cancellationState_, WAITING_FOR_CHECK);
}

// _____________________________________________________________________________

TEST(CancellationHandle, expectDisabledHandleIsAlwaysFalse) {
CancellationHandle<DISABLED> handle;

Expand Down

0 comments on commit 365469e

Please sign in to comment.