summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChayim I. Kirshen <c@kirshen.com>2023-04-04 09:39:13 +0300
committerChayim I. Kirshen <c@kirshen.com>2023-04-04 09:39:13 +0300
commite48233d1cfecb8efe43f197d8a4acc566c31fb70 (patch)
tree28f43b5d5fd3ef8c5826ab4883c5575ceeb1fda9
parent02d3cc30754155f58f672e5394df2c02702064cf (diff)
downloadredis-py-e48233d1cfecb8efe43f197d8a4acc566c31fb70.tar.gz
lint and ensure_future
-rw-r--r--tests/test_asyncio/test_cwe_404.py31
1 files changed, 13 insertions, 18 deletions
diff --git a/tests/test_asyncio/test_cwe_404.py b/tests/test_asyncio/test_cwe_404.py
index 219984e..19ec9dd 100644
--- a/tests/test_asyncio/test_cwe_404.py
+++ b/tests/test_asyncio/test_cwe_404.py
@@ -27,35 +27,30 @@ class DelayProxy:
async def start(self):
self.server = await asyncio.start_server(self.handle, *self.addr)
- self.ROUTINE = asyncio.create_task(self.server.serve_forever())
-
- # async def handle(self, reader, writer):
- # # establish connection to redis
- # redis_reader, redis_writer = await asyncio.open_connection(*self.redis_addr)
- # pipe1 = asyncio.create_task(pipe(reader, redis_writer, self.delay, "to redis:"))
- # pipe2 = asyncio.create_task(
- # pipe(redis_reader, writer, self.delay, "from redis:")
- # )
- # await asyncio.gather(pipe1, pipe2)
+ self.ROUTINE = asyncio.ensure_future(self.server.serve_forever())
async def handle(self, reader, writer):
# establish connection to redis
- print('new connection')
+ print("new connection")
redis_reader, redis_writer = await asyncio.open_connection(*self.redis_addr)
- pipe1 = asyncio.ensure_future(pipe(reader, redis_writer, self.delay, 'to redis:'))
- pipe2 = asyncio.ensure_future(pipe(redis_reader, writer, self.delay, 'from redis:'))
+ pipe1 = asyncio.ensure_future(
+ pipe(reader, redis_writer, self.delay, "to redis:")
+ )
+ pipe2 = asyncio.ensure_future(
+ pipe(redis_reader, writer, self.delay, "from redis:")
+ )
try:
await pipe1
finally:
pipe2.cancel()
await pipe2
-
+
async def stop(self):
# clean up enough so that we can reuse the looper
self.ROUTINE.cancel()
loop = self.server.get_loop()
await loop.shutdown_asyncgens()
-
+
@pytest.mark.asyncio
@pytest.mark.onlynoncluster
@@ -76,7 +71,7 @@ async def test_standalone(delay):
await r.set("foo", "foo")
await r.set("bar", "bar")
- t = asyncio.create_task(r.get("foo"))
+ t = asyncio.ensure_future(r.get("foo"))
await asyncio.sleep(delay)
t.cancel()
try:
@@ -113,7 +108,7 @@ async def test_standalone_pipeline(delay):
pipe2.ping()
pipe2.get("foo")
- t = asyncio.create_task(pipe.get("foo").execute())
+ t = asyncio.ensure_future(pipe.get("foo").execute())
await asyncio.sleep(delay)
t.cancel()
@@ -146,7 +141,7 @@ async def test_cluster(request):
await r.set("foo", "foo")
await r.set("bar", "bar")
- t = asyncio.create_task(r.get("foo"))
+ t = asyncio.ensure_future(r.get("foo"))
await asyncio.sleep(0.050)
t.cancel()
try: