Skip to content

Commit e1b895a

Browse files
committed
Fix resource missing awaits in test_cwe_404
1 parent 19467de commit e1b895a

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
@@ -213,8 +213,9 @@ def all_clear():
213213
p.send_event.clear()
214214

215215
async def wait_for_send():
216-
asyncio.wait(
217-
[p.send_event.wait() for p in proxies], return_when=asyncio.FIRST_COMPLETED
216+
await asyncio.wait(
217+
[asyncio.Task(p.send_event.wait()) for p in proxies],
218+
return_when=asyncio.FIRST_COMPLETED,
218219
)
219220

220221
@contextlib.contextmanager
@@ -228,11 +229,10 @@ def set_delay(delay: float):
228229
for p in proxies:
229230
await stack.enter_async_context(p)
230231

231-
with contextlib.closing(
232-
RedisCluster.from_url(
233-
f"redis://127.0.0.1:{remap_base}", address_remap=remap
234-
)
235-
) as r:
232+
r = RedisCluster.from_url(
233+
f"redis://127.0.0.1:{remap_base}", address_remap=remap
234+
)
235+
try:
236236
await r.initialize()
237237
await r.set("foo", "foo")
238238
await r.set("bar", "bar")
@@ -257,3 +257,5 @@ async def doit():
257257
assert await r.get("foo") == b"foo"
258258

259259
await asyncio.gather(*[doit() for _ in range(10)])
260+
finally:
261+
await r.close()

0 commit comments

Comments
 (0)