Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Unified Diff: mojo/public/cpp/utility/tests/run_loop_unittest.cc

Issue 588593002: mojo: Allow basic RunLoop to be quit from a posted task. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Follow review Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/utility/tests/run_loop_unittest.cc
diff --git a/mojo/public/cpp/utility/tests/run_loop_unittest.cc b/mojo/public/cpp/utility/tests/run_loop_unittest.cc
index d9f754c66d3fde8245fbc03651a34a5a1829ff36..e11c4188d701e0556c66f517816a1a5f396912cb 100644
--- a/mojo/public/cpp/utility/tests/run_loop_unittest.cc
+++ b/mojo/public/cpp/utility/tests/run_loop_unittest.cc
@@ -413,5 +413,42 @@ TEST_F(RunLoopTest, DelayedTaskOrder) {
EXPECT_EQ(3, sequence[2]);
}
+struct QuittingTask {
+ QuittingTask(RunLoop* run_loop) : run_loop(run_loop) {}
+
+ void Run() const { run_loop->Quit(); }
+
+ RunLoop* run_loop;
+};
+
+struct ClosingTask {
+ public:
+ ClosingTask(ScopedMessagePipeHandle* handle): handle(handle) {}
+
+ void Run() const {
+ handle->reset();
+ }
+
+ ScopedMessagePipeHandle* handle;
+};
+
+TEST_F(RunLoopTest, QuitFromDelayedTask) {
+ TestRunLoopHandler handler;
+ MessagePipe test_pipe;
+ RunLoop run_loop;
+ run_loop.AddHandler(&handler,
+ test_pipe.handle0.get(),
+ MOJO_HANDLE_SIGNAL_READABLE,
+ MOJO_DEADLINE_INDEFINITE);
+ run_loop.PostDelayedTask(Closure(QuittingTask(&run_loop)), 0);
+ // Ensure the test won't block forever.
+ run_loop.PostDelayedTask(Closure(ClosingTask(&test_pipe.handle1)), 1e5);
jamesr 2014/09/22 22:30:18 hmm, 1e5 microseconds = 100ms if i'm not mistaken.
+ const MojoTimeTicks before = GetTimeTicksNow();
+ run_loop.Run();
+ const MojoTimeTicks after = GetTimeTicksNow();
+ // Check that the run loop did quit before the closing task was run.
+ ASSERT_LE(after-before, 5e4);
jamesr 2014/09/22 22:30:18 this is super racy. if you want tests like this we
qsr 2014/09/23 10:40:15 I didn't want to count on timeout because in case
+}
+
} // namespace
} // namespace mojo
« mojo/public/cpp/utility/lib/run_loop.cc ('K') | « mojo/public/cpp/utility/lib/run_loop.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698