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 |