예제 #1
0
 def test_duplicate(self):
     futures = [Future()] * 5
     result = []
     def waiter():
         result.append(gruvi.wait(futures))
     fib = Fiber(waiter)
     fib.start()
     gruvi.sleep(0)
     self.assertEqual(result, [])
     futures[0].set_result(None)
     gruvi.sleep(0)
     self.assertEqual(result, [(futures, [])])
예제 #2
0
    def test_duplicate(self):
        futures = [Future()] * 5
        result = []

        def waiter():
            result.append(gruvi.wait(futures))

        fib = Fiber(waiter)
        fib.start()
        gruvi.sleep(0)
        self.assertEqual(result, [])
        futures[0].set_result(None)
        gruvi.sleep(0)
        self.assertEqual(result, [(futures, [])])
예제 #3
0
 def test_partial(self):
     # Ensure that the "count" argument of wait() can be used to wait for a
     # subset of the futures to complete.
     futures = [Future() for i in range(10)]
     result = []
     def waiter():
         result.append(gruvi.wait(futures, count=5))
     fib = Fiber(waiter)
     fib.start()
     gruvi.sleep(0)
     for i in range(4):
         futures[i].set_result(None)
     self.assertTrue(fib.alive)
     self.assertEqual(result, [])
     futures[4].set_result(None)
     gruvi.sleep(0)
     self.assertFalse(fib.alive)
     self.assertEqual(result, [(futures[:5], futures[5:])])
예제 #4
0
 def test_basic(self):
     # Simple wait() test waiting for two futures.
     futures = [Future() for i in range(2)]
     result = []
     def waiter():
         result.append(gruvi.wait(futures))
     fib = Fiber(waiter)
     fib.start()
     gruvi.sleep(0)
     self.assertTrue(fib.alive)
     self.assertEqual(result, [])
     futures[0].set_result(None)
     gruvi.sleep(0)
     self.assertTrue(fib.alive)
     futures[1].set_result(None)
     gruvi.sleep(0)
     self.assertFalse(fib.alive)
     self.assertEqual(result, [(futures, [])])
예제 #5
0
    def test_partial(self):
        # Ensure that the "count" argument of wait() can be used to wait for a
        # subset of the futures to complete.
        futures = [Future() for i in range(10)]
        result = []

        def waiter():
            result.append(gruvi.wait(futures, count=5))

        fib = Fiber(waiter)
        fib.start()
        gruvi.sleep(0)
        for i in range(4):
            futures[i].set_result(None)
        self.assertTrue(fib.alive)
        self.assertEqual(result, [])
        futures[4].set_result(None)
        gruvi.sleep(0)
        self.assertFalse(fib.alive)
        self.assertEqual(result, [(futures[:5], futures[5:])])
예제 #6
0
    def test_basic(self):
        # Simple wait() test waiting for two futures.
        futures = [Future() for i in range(2)]
        result = []

        def waiter():
            result.append(gruvi.wait(futures))

        fib = Fiber(waiter)
        fib.start()
        gruvi.sleep(0)
        self.assertTrue(fib.alive)
        self.assertEqual(result, [])
        futures[0].set_result(None)
        gruvi.sleep(0)
        self.assertTrue(fib.alive)
        futures[1].set_result(None)
        gruvi.sleep(0)
        self.assertFalse(fib.alive)
        self.assertEqual(result, [(futures, [])])
예제 #7
0
    def test_object_types(self):
        def sleeper():
            gruvi.sleep(0.1)

        objects = []
        for i in range(2):
            fib = Fiber(sleeper)
            fib.start()
            objects.append(fib)
        for i in range(2):
            objects.append(Event())
        for i in range(2):
            objects.append(Future())
        for i in range(2):
            proc = Process()
            proc.spawn('true')
            objects.append(proc)
        result = []

        def waiter():
            result.append(gruvi.wait(objects))

        fib = Fiber(waiter)
        fib.start()
        gruvi.sleep(0)
        self.assertTrue(fib.alive)
        objects[2].set()
        objects[3].set()
        objects[4].set_result(True)
        objects[5].set_exception(RuntimeError)
        fib.join()
        self.assertFalse(fib.alive)
        self.assertEqual(set(result[0][0]), set(objects))
        self.assertFalse(objects[0].alive)
        self.assertFalse(objects[1].alive)
        self.assertEqual(objects[6].returncode, 0)
        self.assertEqual(objects[7].returncode, 0)
        for obj in objects:
            self.assertIsNone(obj._callbacks)
        objects[6].close()
        objects[7].close()
예제 #8
0
 def test_object_types(self):
     def sleeper():
         gruvi.sleep(0.1)
     objects = []
     for i in range(2):
         fib = Fiber(sleeper)
         fib.start()
         objects.append(fib)
     for i in range(2):
         objects.append(Event())
     for i in range(2):
         objects.append(Future())
     for i in range(2):
         proc = Process()
         proc.spawn('true')
         objects.append(proc)
     result = []
     def waiter():
         result.append(gruvi.wait(objects))
     fib = Fiber(waiter)
     fib.start()
     gruvi.sleep(0)
     self.assertTrue(fib.alive)
     objects[2].set()
     objects[3].set()
     objects[4].set_result(True)
     objects[5].set_exception(RuntimeError)
     fib.join()
     self.assertFalse(fib.alive)
     self.assertEqual(set(result[0][0]), set(objects))
     self.assertFalse(objects[0].alive)
     self.assertFalse(objects[1].alive)
     self.assertEqual(objects[6].returncode, 0)
     self.assertEqual(objects[7].returncode, 0)
     for obj in objects:
         self.assertFalse(obj._callbacks)
     objects[6].close()
     objects[7].close()