ce29517998
Summary: Utils source files are now moved to a standalone mg-utils library. Unit and manual tests are no longer collected using glob recursion in cmake, but are explicitly listed. This allows us to set only required dependencies of those tests. Both of these changes should improve compilation and link times, as well as lower the disk usage. Additional improvement would be to cleanup utils header files to be split in .hpp and .cpp as well as merging threading into utils. Other potential library extractions that shouldn't be difficult are: * data_structures * io/network * communication Reviewers: buda, mferencevic, dgleich, ipaljak, mculinovic, mtomic, msantl Reviewed By: buda Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D1408
60 lines
1.1 KiB
C++
60 lines
1.1 KiB
C++
#include <atomic>
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include "utils/watchdog.hpp"
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
TEST(Watchdog, Run) {
|
|
std::atomic<int> count(0);
|
|
utils::Watchdog dog(200ms, 200ms, [&count]() { ++count; });
|
|
|
|
std::this_thread::sleep_for(250ms);
|
|
EXPECT_EQ(count, 1);
|
|
|
|
std::this_thread::sleep_for(200ms);
|
|
EXPECT_EQ(count, 2);
|
|
|
|
std::this_thread::sleep_for(50ms);
|
|
dog.Notify();
|
|
|
|
std::this_thread::sleep_for(150ms);
|
|
EXPECT_EQ(count, 2);
|
|
dog.Notify();
|
|
|
|
std::this_thread::sleep_for(250ms);
|
|
EXPECT_EQ(count, 3);
|
|
}
|
|
|
|
TEST(Watchdog, Blocker) {
|
|
std::atomic<int> count(0);
|
|
utils::Watchdog dog(200ms, 200ms, [&count]() { ++count; });
|
|
|
|
std::this_thread::sleep_for(250ms);
|
|
EXPECT_EQ(count, 1);
|
|
|
|
dog.Block();
|
|
|
|
std::this_thread::sleep_for(200ms);
|
|
EXPECT_EQ(count, 1);
|
|
|
|
std::this_thread::sleep_for(200ms);
|
|
EXPECT_EQ(count, 1);
|
|
|
|
dog.Unblock();
|
|
|
|
std::this_thread::sleep_for(150ms);
|
|
EXPECT_EQ(count, 1);
|
|
|
|
std::this_thread::sleep_for(100ms);
|
|
EXPECT_EQ(count, 2);
|
|
dog.Notify();
|
|
|
|
std::this_thread::sleep_for(100ms);
|
|
dog.Unblock();
|
|
|
|
std::this_thread::sleep_for(150ms);
|
|
EXPECT_EQ(count, 3);
|
|
}
|