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 make_completed_future(result, exception=False): """Make a future completed with a given result.""" future = futures.Future() if exception: future.set_exception(result) else: future.set_result(result) return future
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)