Skip to content

Commit 74fde39

Browse files
committed
test: verify AsyncStream.aclose() closes all child httpx clients
Tests that main, video, and chat httpx clients are closed after aclose(), and that aclose() works when child clients were never accessed (cached_property not triggered).
1 parent aaed925 commit 74fde39

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/test_async_stream_close.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import pytest
2+
3+
from getstream import AsyncStream
4+
5+
6+
@pytest.mark.asyncio
7+
class TestAsyncStreamClose:
8+
async def test_aclose_closes_main_client(self):
9+
client = AsyncStream(api_key="fake", api_secret="fake")
10+
11+
assert client.client.is_closed is False
12+
await client.aclose()
13+
assert client.client.is_closed is True
14+
15+
async def test_aclose_closes_video_client(self):
16+
client = AsyncStream(api_key="fake", api_secret="fake")
17+
_ = client.video # trigger cached_property
18+
19+
assert client.video.client.is_closed is False
20+
await client.aclose()
21+
assert client.video.client.is_closed is True
22+
23+
async def test_aclose_closes_chat_client(self):
24+
client = AsyncStream(api_key="fake", api_secret="fake")
25+
_ = client.chat
26+
27+
assert client.chat.client.is_closed is False
28+
await client.aclose()
29+
assert client.chat.client.is_closed is True
30+
31+
async def test_aclose_without_child_clients(self):
32+
"""aclose() should work even if video/chat were never accessed."""
33+
client = AsyncStream(api_key="fake", api_secret="fake")
34+
await client.aclose()
35+
assert client.client.is_closed is True

0 commit comments

Comments
 (0)