Skip to content

Commit c383b83

Browse files
committed
Fix resource missing awaits in test_cwe_404
1 parent 004e15e commit c383b83

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

tests/test_asyncio/test_cluster.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def cmd_init_mock(self, r: ClusterNode) -> None:
175175

176176

177177
def mock_node_resp(node: ClusterNode, response: Any) -> ClusterNode:
178-
connection = mock.AsyncMock()
178+
connection = mock.AsyncMock(spec=Connection)
179179
connection.is_connected = True
180180
connection.read_response.return_value = response
181181
while node._free:
@@ -185,7 +185,7 @@ def mock_node_resp(node: ClusterNode, response: Any) -> ClusterNode:
185185

186186

187187
def mock_node_resp_exc(node: ClusterNode, exc: Exception) -> ClusterNode:
188-
connection = mock.AsyncMock()
188+
connection = mock.AsyncMock(spec=Connection)
189189
connection.is_connected = True
190190
connection.read_response.side_effect = exc
191191
while node._free:

tests/test_asyncio/test_cwe_404.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,9 @@ def all_clear():
204204
p.send_event.clear()
205205

206206
async def wait_for_send():
207-
asyncio.wait(
208-
[p.send_event.wait() for p in proxies], return_when=asyncio.FIRST_COMPLETED
207+
await asyncio.wait(
208+
[asyncio.Task(p.send_event.wait()) for p in proxies],
209+
return_when=asyncio.FIRST_COMPLETED,
209210
)
210211

211212
@contextlib.contextmanager
@@ -219,11 +220,10 @@ def set_delay(delay: float):
219220
for p in proxies:
220221
await stack.enter_async_context(p)
221222

222-
with contextlib.closing(
223-
RedisCluster.from_url(
224-
f"redis://127.0.0.1:{remap_base}", address_remap=remap
225-
)
226-
) as r:
223+
r = RedisCluster.from_url(
224+
f"redis://127.0.0.1:{remap_base}", address_remap=remap
225+
)
226+
try:
227227
await r.initialize()
228228
await r.set("foo", "foo")
229229
await r.set("bar", "bar")
@@ -248,3 +248,5 @@ async def doit():
248248
assert await r.get("foo") == b"foo"
249249

250250
await asyncio.gather(*[doit() for _ in range(10)])
251+
finally:
252+
await r.close()

0 commit comments

Comments
 (0)