def test_all_completed_class_method(self): """ Test the 'all_completed' class method """ responses = [] for i in range(10): responses.append(AsyncResponse()) # Create a method that will be executed on a different thread # And resolve each async response def resolver(): time.sleep(1) for i in responses: i.resolve(TEST_RESPONSE) # Start the resolving thread threading.Thread(target=resolver).start() results = AsyncResponse.all_completed(responses) self.assertEquals(len(results), len(responses)) for i in results: self.assertEquals(i, TEST_RESPONSE)
def test_all_completed_with_timeout(self): """ Test the 'all_completed' class method """ responses = [] for i in range(10): responses.append(AsyncResponse()) # Create a method that will be executed on a different thread # And resolve each async response def resolver(): time.sleep(10) for i in responses: i.resolve(TEST_RESPONSE) # Start the resolving thread t = threading.Thread(target=resolver) t.daemon = True t.start() results = AsyncResponse.all_completed(responses, timeout=1)