From ae45a7872db3ae2a40e5fc2da0f0db646258d1f2 Mon Sep 17 00:00:00 2001 From: voluntas Date: Mon, 30 Sep 2024 16:04:55 +0900 Subject: [PATCH] =?UTF-8?q?disconnect=20=E3=81=AE=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/client.py | 12 +++++++++++- tests/test_disconnect.py | 42 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/test_disconnect.py diff --git a/tests/client.py b/tests/client.py index 1de2562..30b0fe8 100644 --- a/tests/client.py +++ b/tests/client.py @@ -45,6 +45,9 @@ def __init__( self._signaling_urls: list[str] = signaling_urls self._channel_id: str = channel_id + self._audio = audio + self._video = video + self._audio_channels: int = audio_channels self._audio_sample_rate: int = audio_sample_rate @@ -104,6 +107,14 @@ def __init__( self._connection.on_disconnect = self._on_disconnect self._connection.on_ws_close = self._on_ws_close + def __enter__(self): + print(f"self._audio: {self._audio}") + print(f"self._video: {self._video}") + return self.connect(fake_audio=bool(self._audio), fake_video=bool(self._video)) + + def __exit__(self, exc_type, exc_value, traceback): + self.disconnect() + def connect(self, fake_audio=False, fake_video=False) -> None: self._connection.connect() @@ -120,7 +131,6 @@ def connect(self, fake_audio=False, fake_video=False) -> None: ), "Could not connect to Sora." def disconnect(self) -> None: - """Sora から切断します。""" self._connection.disconnect() def get_stats(self): diff --git a/tests/test_disconnect.py b/tests/test_disconnect.py new file mode 100644 index 0000000..f73c7ee --- /dev/null +++ b/tests/test_disconnect.py @@ -0,0 +1,42 @@ +import sys +import uuid + +from client import Sendonly + + +def test_sendonly_disconnect(setup): + signaling_urls = setup.get("signaling_urls") + channel_id_prefix = setup.get("channel_id_prefix") + metadata = setup.get("metadata") + + channel_id = f"{channel_id_prefix}_{__name__}_{sys._getframe().f_code.co_name}_{uuid.uuid4()}" + + with Sendonly( + signaling_urls, + channel_id, + audio=True, + video=True, + metadata=metadata, + ) as sendonly1: + with Sendonly( + signaling_urls, + channel_id, + audio=True, + video=True, + metadata=metadata, + ) as sendonly2: + with Sendonly( + signaling_urls, + channel_id, + audio=True, + video=True, + metadata=metadata, + ) as sendonly3: + with Sendonly( + signaling_urls, + channel_id, + audio=True, + video=True, + metadata=metadata, + ) as sendonly4: + pass