Beispiel #1
0
    def test_event_basic(self):
        event = MotorGreenletEvent(self.io_loop, tornado_framework)
        self.assertFalse(event.is_set())

        waiter = greenlet.greenlet(event.wait)
        waiter.switch()
        yield self.tick()
        self.assertTrue(waiter)  # Blocked: not finished yet.
        event.set()
        yield self.tick()
        self.assertFalse(waiter)  # Complete.

        self.assertTrue(event.is_set())
Beispiel #2
0
    def test_event_multi(self):
        # Two greenlets are run, FIFO, after being unblocked.
        event = MotorGreenletEvent(self.io_loop, tornado_framework)
        order = []

        def wait():
            event.wait()
            order.append(greenlet.getcurrent())

        waiter0 = greenlet.greenlet(wait)
        waiter1 = greenlet.greenlet(wait)
        waiter0.switch()
        waiter1.switch()
        event.set()
        yield self.tick()
        self.assertEqual([waiter0, waiter1], order)
Beispiel #3
0
 def test_event_timeout(self):
     event = MotorGreenletEvent(self.io_loop, tornado_framework)
     waiter = greenlet.greenlet(partial(event.wait, timeout_seconds=0))
     waiter.switch()
     yield self.tick()
     self.assertFalse(waiter)  # Unblocked, finished.