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

Side by Side Diff: mojo/python/tests/async_wait_unittest.py

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, 2 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 unified diff | Download patch
« no previous file with comments | « mojo/public/cpp/utility/tests/run_loop_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import unittest 5 import unittest
6 6
7 # pylint: disable=F0401 7 # pylint: disable=F0401
8 import mojo.embedder 8 import mojo.embedder
9 from mojo import system 9 from mojo import system
10 10
11 11
12 class AsyncWaitTest(unittest.TestCase): 12 class AsyncWaitTest(unittest.TestCase):
13 13
14 def setUp(self): 14 def setUp(self):
15 mojo.embedder.Init() 15 mojo.embedder.Init()
16 self.loop = system.RunLoop() 16 self.loop = system.RunLoop()
17 self.array = [] 17 self.array = []
18 self.handles = system.MessagePipe() 18 self.handles = system.MessagePipe()
19 self.cancel = self.handles.handle0.AsyncWait(system.HANDLE_SIGNAL_READABLE, 19 self.cancel = self.handles.handle0.AsyncWait(system.HANDLE_SIGNAL_READABLE,
20 system.DEADLINE_INDEFINITE, 20 system.DEADLINE_INDEFINITE,
21 self.OnResult) 21 self._OnResult)
22 self.loop.PostDelayedTask(self.WriteToHandle, 100)
23 22
24 def tearDown(self): 23 def tearDown(self):
24 self.cancel()
25 self.handles = None 25 self.handles = None
26 self.array = None 26 self.array = None
27 self.loop = None 27 self.loop = None
28 28
29 def OnResult(self, value): 29 def _OnResult(self, value):
30 self.array.append(value) 30 self.array.append(value)
31 31
32 def WriteToHandle(self): 32 def _WriteToHandle(self):
33 self.handles.handle1.WriteMessage() 33 self.handles.handle1.WriteMessage()
34 34
35 def _PostWriteAndRun(self):
36 self.loop.PostDelayedTask(self._WriteToHandle, 0)
37 self.loop.RunUntilIdle()
38
35 def testAsyncWait(self): 39 def testAsyncWait(self):
36 self.loop.RunUntilIdle() 40 self._PostWriteAndRun()
37 self.assertEquals(len(self.array), 1) 41 self.assertEquals(len(self.array), 1)
38 self.assertEquals(system.RESULT_OK, self.array[0]) 42 self.assertEquals(system.RESULT_OK, self.array[0])
39 self.cancel()
40 43
41 def testAsyncWaitCancel(self): 44 def testAsyncWaitCancel(self):
42 self.loop.PostDelayedTask(self.cancel, 50) 45 self.loop.PostDelayedTask(self.cancel, 0)
43 self.loop.RunUntilIdle() 46 self._PostWriteAndRun()
44 self.assertEquals(len(self.array), 0) 47 self.assertEquals(len(self.array), 0)
45 self.cancel()
46 48
47 def testAsyncWaitImmediateCancel(self): 49 def testAsyncWaitImmediateCancel(self):
48 self.cancel() 50 self.cancel()
49 self.loop.RunUntilIdle() 51 self._PostWriteAndRun()
50 self.assertEquals(len(self.array), 0) 52 self.assertEquals(len(self.array), 0)
51 self.cancel()
OLDNEW
« no previous file with comments | « mojo/public/cpp/utility/tests/run_loop_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698