async def test_successful_requests_return_if_no_pending_requests( self, loop): h = HammerTime(loop=loop, request_engine=FakeEngine()) h.collect_successful_requests() try: with async_timeout.timeout(0.001): async for entry in h.successful_requests(): entry.request except asyncio.TimeoutError: self.fail("Function blocked.")
async def test_loop_over_results(self, loop): h = HammerTime(loop=loop, request_engine=FakeEngine()) h.request("http://example.com/1") h.request("http://example.com/2") out = set() async for entry in h.successful_requests(): out.add(entry.response.content) self.assertEqual(out, {"http://example.com/1", "http://example.com/2"}) self.assertEqual(h.completed_count, 2)
async def test_skip_results_that_fail(self, loop): h = HammerTime(loop=loop, request_engine=FakeEngine()) h.heuristics.add(BlockRequest("http://example.com/1")) h.request("http://example.com/1") h.request("http://example.com/2") out = set() async for entry in h.successful_requests(): out.add(entry.response.content) self.assertEqual(out, {"http://example.com/2"}) self.assertEqual(h.completed_count, 2)
async def test_no_successful_request_returned_when_requests_are_cancelled( self, loop): engine = MagicMock() engine.perform = make_mocked_coro( raise_exception=asyncio.CancelledError) hammertime = HammerTime(loop=loop, request_engine=engine) for i in range(5): hammertime.request("http://example.com") successful_requests = [] async for request in hammertime.successful_requests(): successful_requests.append(request) self.assertEqual(successful_requests, [])