Skip to content

Commit

Permalink
More cleanup (tests/...) of deprecated loop= arguments for asyncio.Qu…
Browse files Browse the repository at this point in the history
…eue, asyncio.sleep.
  • Loading branch information
moodyjon committed Jul 10, 2022
1 parent 38797f6 commit f46a9dc
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion tests/integration/datanetwork/test_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,6 @@ async def test_range_requests_with_blob_lru_cache(self):

# running with cache size 0 gets through without errors without
# this since the server doesn't stop immediately
await asyncio.sleep(1, loop=self.loop)
await asyncio.sleep(1)

await self._request_stream()
6 changes: 3 additions & 3 deletions tests/unit/blob/test_blob_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def _test_create_blob(self, blob_class=AbstractBlob, blob_directory=None):
writer.write(self.blob_bytes)
await blob.verified.wait()
self.assertTrue(blob.get_is_verified())
await asyncio.sleep(0, loop=self.loop) # wait for the db save task
await asyncio.sleep(0) # wait for the db save task
return blob

async def _test_close_writers_on_finished(self, blob_class=AbstractBlob, blob_directory=None):
Expand All @@ -48,7 +48,7 @@ async def _test_close_writers_on_finished(self, blob_class=AbstractBlob, blob_di
with self.assertRaises(InvalidDataError):
writers[1].write(self.blob_bytes * 2)
await writers[1].finished
await asyncio.sleep(0, loop=self.loop)
await asyncio.sleep(0)
self.assertEqual(4, len(blob.writers))

# write the blob
Expand Down Expand Up @@ -208,7 +208,7 @@ async def _test_close_reader(self, blob_class=AbstractBlob, blob_directory=None)
async def read_blob_buffer():
with reader as read_handle:
self.assertEqual(1, len(blob.readers))
await asyncio.sleep(2, loop=self.loop)
await asyncio.sleep(2)
self.assertEqual(0, len(blob.readers))
return read_handle.read()

Expand Down
12 changes: 6 additions & 6 deletions tests/unit/blob_exchange/test_transfer_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ async def _inner():
writer.write(mock_blob_bytes)
return self.loop.create_task(_inner())

await asyncio.gather(write_task(writer1), write_task(writer2), loop=self.loop)
await asyncio.gather(write_task(writer1), write_task(writer2))

self.assertDictEqual({1: mock_blob_bytes, 2: mock_blob_bytes}, results)
self.assertEqual(1, write_called_count)
Expand Down Expand Up @@ -270,7 +270,7 @@ async def test_idle_timeout(self):
client_blob.delete()

# wait for less than the idle timeout
await asyncio.sleep(0.5, loop=self.loop)
await asyncio.sleep(0.5)

# download the blob again
downloaded, protocol2 = await request_blob(self.loop, client_blob, self.server_from_client.address,
Expand All @@ -284,10 +284,10 @@ async def test_idle_timeout(self):
client_blob.delete()

# check that the connection times out from the server side
await asyncio.sleep(0.9, loop=self.loop)
await asyncio.sleep(0.9)
self.assertFalse(protocol.transport.is_closing())
self.assertIsNotNone(protocol.transport._sock)
await asyncio.sleep(0.1, loop=self.loop)
await asyncio.sleep(0.1)
self.assertIsNone(protocol.transport)

def test_max_request_size(self):
Expand Down Expand Up @@ -323,7 +323,7 @@ async def test_transfer_timeout(self):
server_blob = self.server_blob_manager.get_blob(blob_hash)

async def sendfile(writer):
await asyncio.sleep(2, loop=self.loop)
await asyncio.sleep(2)
return 0

server_blob.sendfile = sendfile
Expand All @@ -347,7 +347,7 @@ async def test_download_blob_using_jsonrpc_blob_get(self):
def _mock_accumulate_peers(q1, q2=None):
async def _task():
pass
q2 = q2 or asyncio.Queue(loop=self.loop)
q2 = q2 or asyncio.Queue()
return q2, self.loop.create_task(_task())

mock_node.accumulate_peers = _mock_accumulate_peers
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/core/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ def setUp(self):
@utils.cache_concurrent
async def foo(self, arg1, arg2=None, delay=1):
self.called.append((arg1, arg2, delay))
await asyncio.sleep(delay, loop=self.loop)
await asyncio.sleep(delay)
self.counter += 1
self.finished.append((arg1, arg2, delay))
return object()

async def test_gather_duplicates(self):
result = await asyncio.gather(
self.loop.create_task(self.foo(1)), self.loop.create_task(self.foo(1)), loop=self.loop
self.loop.create_task(self.foo(1)), self.loop.create_task(self.foo(1))
)
self.assertEqual(1, len(self.called))
self.assertEqual(1, len(self.finished))
Expand All @@ -93,7 +93,7 @@ async def test_one_cancelled_all_cancel(self):

with self.assertRaises(asyncio.CancelledError):
await asyncio.gather(
t1, self.loop.create_task(self.foo(1)), loop=self.loop
t1, self.loop.create_task(self.foo(1))
)
self.assertEqual(1, len(self.called))
self.assertEqual(0, len(self.finished))
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/dht/test_blob_announcer.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async def test_announce_blobs(self):
await self.chain_peer(constants.generate_id(current + 4), '1.2.3.13')
last = await self.chain_peer(constants.generate_id(current + 5), '1.2.3.14')

search_q, peer_q = asyncio.Queue(loop=self.loop), asyncio.Queue(loop=self.loop)
search_q, peer_q = asyncio.Queue(), asyncio.Queue()
search_q.put_nowait(blob1)

_, task = last.accumulate_peers(search_q, peer_q)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/stream/test_managed_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ async def test_delayed_stop(self):
await self._test_transfer_stream(10, stop_when_done=False)
self.assertEqual(self.stream.status, "finished")
self.assertTrue(self.stream._running.is_set())
await asyncio.sleep(0.5, loop=self.loop)
await asyncio.sleep(0.5)
self.assertTrue(self.stream._running.is_set())
await asyncio.sleep(2, loop=self.loop)
await asyncio.sleep(2)
self.assertEqual(self.stream.status, "finished")
self.assertFalse(self.stream._running.is_set())

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/stream/test_reflector.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ async def _test_reflect_stream(self, response_chunk_size=50, partial_needs=False
self.assertListEqual(sent, [])

async def test_reflect_stream(self):
return await asyncio.wait_for(self._test_reflect_stream(response_chunk_size=50), 3, loop=self.loop)
return await asyncio.wait_for(self._test_reflect_stream(response_chunk_size=50), 3)

async def test_reflect_stream_but_reflector_changes_its_mind(self):
return await asyncio.wait_for(self._test_reflect_stream(partial_needs=True), 3, loop=self.loop)
return await asyncio.wait_for(self._test_reflect_stream(partial_needs=True), 3)

async def test_reflect_stream_small_response_chunks(self):
return await asyncio.wait_for(self._test_reflect_stream(response_chunk_size=30), 3, loop=self.loop)
return await asyncio.wait_for(self._test_reflect_stream(response_chunk_size=30), 3)

async def test_announces(self):
to_announce = await self.storage.get_blobs_to_announce()
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/stream/test_stream_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ async def _check_post(event):
await self.file_manager.download_from_uri(self.uri, self.exchange_rate_manager)
else:
await self.file_manager.download_from_uri(self.uri, self.exchange_rate_manager)
await asyncio.sleep(0, loop=self.loop)
await asyncio.sleep(0)
self.assertTrue(checked_analytics_event)

async def test_time_to_first_bytes(self):
Expand Down Expand Up @@ -317,7 +317,7 @@ async def check_post(event):
stream.downloader.node = self.stream_manager.node
await stream.save_file()
await stream.finished_writing.wait()
await asyncio.sleep(0, loop=self.loop)
await asyncio.sleep(0)
self.assertTrue(stream.finished)
self.assertFalse(stream.running)
self.assertTrue(os.path.isfile(os.path.join(self.client_dir, "test_file")))
Expand Down Expand Up @@ -355,7 +355,7 @@ async def check_post(event):

self.stream_manager.analytics_manager._post = check_post
await self._test_download_error_on_start(expected_error, timeout)
await asyncio.sleep(0, loop=self.loop)
await asyncio.sleep(0)
self.assertListEqual([expected_error.__name__], received)

async def test_insufficient_funds(self):
Expand Down Expand Up @@ -448,7 +448,7 @@ async def check_post(event):
self.assertDictEqual(self.stream_manager.streams, {})
stream = await self.file_manager.download_from_uri(self.uri, self.exchange_rate_manager)
await stream.finished_writing.wait()
await asyncio.sleep(0, loop=self.loop)
await asyncio.sleep(0)
await self.stream_manager.stop()
self.client_blob_manager.stop()
# partial removal, only sd blob is missing.
Expand Down

0 comments on commit f46a9dc

Please sign in to comment.