Exemplo n.º 1
0
 def testRunLoop(self):
     loop = system.RunLoop()
     array = []
     for _ in xrange(10):
         loop.PostDelayedTask(_Increment(array))
     loop.RunUntilIdle()
     self.assertEquals(len(array), 10)
 def setUp(self):
     mojo.embedder.Init()
     self.loop = system.RunLoop()
     self.array = []
     self.handles = system.MessagePipe()
     self.cancel = self.handles.handle0.AsyncWait(
         system.HANDLE_SIGNAL_READABLE, system.DEADLINE_INDEFINITE,
         self._OnResult)
Exemplo n.º 3
0
    def testRunLoopWithException(self):
        loop = system.RunLoop()

        def Throw():
            raise Exception("error")

        array = []
        loop.PostDelayedTask(Throw)
        loop.PostDelayedTask(_Increment(array))
        with self.assertRaisesRegexp(Exception, '^error$'):
            loop.Run()
        self.assertEquals(len(array), 0)
        loop.RunUntilIdle()
        self.assertEquals(len(array), 1)
Exemplo n.º 4
0
    def setUp(self):
        mojo.embedder.Init()
        self.loop = system.RunLoop()
        self.received_messages = []
        self.received_errors = []

        def _OnMessage(message):
            self.received_messages.append(message)
            return True

        def _OnError(result):
            self.received_errors.append(result)

        handles = system.MessagePipe()
        self.connector = messaging.Connector(handles.handle1)
        self.connector.SetIncomingMessageReceiver(
            messaging.ForwardingMessageReceiver(_OnMessage))
        self.connector.SetErrorHandler(
            _ForwardingConnectionErrorHandler(_OnError))
        self.connector.Start()
        self.handle = handles.handle0
Exemplo n.º 5
0
 def setUp(self):
     mojo.embedder.Init()
     self.loop = system.RunLoop()