a656ba3343
Summary: Because it was unnecessary and also implemented wrong (if someone tried using a Schduler with something other then std::mutex, it would not compile). We can trivially add this if it ever becomes necessary. Reviewers: buda, mislav.bradac Reviewed By: buda, mislav.bradac Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D666
30 lines
731 B
C++
30 lines
731 B
C++
#include "gmock/gmock.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
#include <atomic>
|
|
#include "utils/scheduler.hpp"
|
|
|
|
/**
|
|
* Scheduler runs every 2 seconds and increases one variable. Test thread
|
|
* increases other variable. Scheduler checks if variables have the same
|
|
* value.
|
|
*/
|
|
TEST(Scheduler, TestFunctionExecuting) {
|
|
std::atomic<int> x{0}, y{0};
|
|
std::function<void()> func{[&x, &y]() {
|
|
EXPECT_EQ(y.load(), x.load());
|
|
x++;
|
|
}};
|
|
Scheduler scheduler;
|
|
scheduler.Run(std::chrono::seconds(1), func);
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(980));
|
|
y++;
|
|
EXPECT_EQ(x.load(), y.load());
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
scheduler.Stop();
|
|
y++;
|
|
EXPECT_EQ(x.load(), y.load());
|
|
}
|