Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: test/SchedulerTest.cpp

Issue 29370876: Issue #4692, #3595 - Stop sleeping in the implementation of `SetTimeout`
Patch Set: Created Jan. 9, 2017, 1:22 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/PausePoint.cpp ('k') | test/TimeoutTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/SchedulerTest.cpp
===================================================================
--- a/test/SchedulerTest.cpp
+++ b/test/SchedulerTest.cpp
@@ -60,17 +60,44 @@
EXPECT_EQ(1, counter);
}
+struct RudimentaryTask
+ : public TaskFunctionInterface
+{
+ std::function<void()> f;
+ RudimentaryTask(std::function<void()> f)
+ : f(f)
+ {}
+ virtual void operator()() override
+ {
+ f();
+ }
+ virtual void Interrupt() override
+ {}
+};
+
+std::shared_ptr<RudimentaryTask> MakeRudimentaryTask(std::function<void()> f)
+{
+ return std::make_shared<RudimentaryTask>(f);
+}
+
+struct NullUserData {};
+
TEST(Scheduler, Instance)
{
- SchedulerT<SingleUseWorker> s;
+ SchedulerT<SingleUseWorker, NullUserData> s;
}
+std::shared_ptr<NullUserData> MakeNullUserData()
+{
+ return std::shared_ptr<NullUserData>();
+}
+
TEST(Scheduler, RunOnce)
{
int counter = 0;
- SchedulerT<SingleUseWorker> s;
+ SchedulerT<SingleUseWorker, NullUserData> s;
EXPECT_EQ(0, counter);
- s.Run([&]() {++counter; });
+ s.Run(MakeRudimentaryTask([&]() {++counter; }), MakeNullUserData());
s.JoinAll();
EXPECT_EQ(1, counter);
}
@@ -78,10 +105,10 @@
TEST(Scheduler, RunTwice)
{
int counter = 0;
- SchedulerT<SingleUseWorker> s;
- s.Run([&]() {++counter; });
+ SchedulerT<SingleUseWorker, NullUserData> s;
+ s.Run(MakeRudimentaryTask([&]() {++counter; }), MakeNullUserData());
s.JoinAll();
- s.Run([&]() {++counter; });
+ s.Run(MakeRudimentaryTask([&]() {++counter; }), MakeNullUserData());
s.JoinAll();
EXPECT_EQ(2, counter);
}
@@ -90,7 +117,7 @@
{
std::mutex m;
int counter = 0;
- SchedulerT<SingleUseWorker> s;
+ SchedulerT<SingleUseWorker, NullUserData> s;
auto f = [&]() {
std::unique_lock<std::mutex> ul(m);
++counter;
@@ -99,7 +126,7 @@
for (int j = 0; j < n; ++j)
{
auto g = f;
- s.Run(g);
+ s.Run(MakeRudimentaryTask(g), MakeNullUserData());
}
ASSERT_NO_THROW(s.JoinAll());
EXPECT_EQ(n, counter);
« no previous file with comments | « test/PausePoint.cpp ('k') | test/TimeoutTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld