def test_mixed_futures(self):
     f1 = futures.Future()
     f2 = futures.Future()
     f2.set_result(1)
     done, not_done = au.wait_for_any([f1, f2], self.timeout)
     self.assertEqual(len(done), 1)
     self.assertEqual(len(not_done), 1)
     self.assertIs(not_done.pop(), f1)
     self.assertIs(done.pop(), f2)
Exemple #2
0
 def test_mixed_futures(self):
     f1 = futures.Future()
     f2 = futures.Future()
     f2.set_result(1)
     done, not_done = au.wait_for_any([f1, f2], self.timeout)
     self.assertEqual(len(done), 1)
     self.assertEqual(len(not_done), 1)
     self.assertIs(not_done.pop(), f1)
     self.assertIs(done.pop(), f2)
    def test_waits_and_finishes(self):
        def foo():
            pass

        with self.executor_cls(2) as e:
            fs = [e.submit(foo), e.submit(foo)]
            # this test assumes that our foo will end within 10 seconds
            done, not_done = au.wait_for_any(fs, 10)
            self.assertIn(len(done), (1, 2))
            self.assertTrue(any(f in done for f in fs))
Exemple #4
0
    def test_waits_and_finishes(self):
        def foo():
            pass

        with self._make_executor(2) as e:
            fs = [e.submit(foo), e.submit(foo)]
            # this test assumes that our foo will end within 10 seconds
            done, not_done = au.wait_for_any(fs, 10)
            self.assertIn(len(done), (1, 2))
            self.assertTrue(any(f in done for f in fs))
    def test_green_waits_and_finishes(self):
        def foo():
            pass

        e = eu.GreenExecutor()

        f1 = e.submit(foo)
        f2 = e.submit(foo)
        # this test assumes that our foo will end within 10 seconds
        done, not_done = au.wait_for_any([f1, f2], 10)
        self.assertIn(len(done), (1, 2))
        self.assertTrue(any((f1 in done, f2 in done)))
    def test_threaded_waits_and_finishes(self):
        def foo():
            pass

        e = futures.ThreadPoolExecutor(2)
        try:
            f1 = e.submit(foo)
            f2 = e.submit(foo)
            # this test assumes that our foo will end within 10 seconds
            done, not_done = au.wait_for_any([f1, f2], 10)
            self.assertIn(len(done), (1, 2))
            self.assertTrue(any((f1 in done, f2 in done)))
        finally:
            e.shutdown()
 def test_not_done_futures(self):
     fs = [futures.Future(), futures.Future()]
     done, not_done = au.wait_for_any(fs, self.timeout)
     self.assertEqual(len(done), 0)
     self.assertEqual(len(not_done), 2)
Exemple #8
0
 def wait_for_any(self, fs, timeout=None):
     return async_utils.wait_for_any(fs, timeout)
Exemple #9
0
 def wait_for_any(self, fs, timeout=None):
     """Wait for futures returned by this executor to complete."""
     return async_utils.wait_for_any(fs, timeout)
Exemple #10
0
 def wait_for_any(self, fs, timeout=None):
     """Wait for futures returned by this executor to complete."""
     return async_utils.wait_for_any(fs, timeout)
Exemple #11
0
 def test_not_done_futures(self):
     fs = [futures.Future(), futures.Future()]
     done, not_done = au.wait_for_any(fs, self.timeout)
     self.assertEqual(len(done), 0)
     self.assertEqual(len(not_done), 2)
Exemple #12
0
 def wait_for_any(self, fs, timeout=None):
     return async_utils.wait_for_any(fs, timeout)