Repository: hikari-py/hikari
Pull request #731 (2021-08-17 12:55:46)

Add missing _check_if_alive to VoiceComponent
### Summary
<!-- Small summary of the merge request -->

### Checklist
<!-- Make sure to tick all the following boxes by putting an `x` in between (like this `[x]`) -->
- [x] I have run `nox` and all the pipelines have passed.
- [x] I have made unittests according to the code I have added/modified/deleted.

### Related issues
<!--
To mention an issue use `#issue-id` and to mention a merge request use `!merge-request-id`
To close/fix an issue use `Close #issue-id` or `Fix #issue-id` (depending on the merge request)
-->



Patch:
diff --git a/hikari/impl/voice.py b/hikari/impl/voice.py
index 219f0a08..9bf17d1d 100644
--- a/hikari/impl/voice.py
+++ b/hikari/impl/voice.py
@@ -95,6 +95,7 @@ async def _disconnect_all(self) -> None:
         await asyncio.gather(*(c.disconnect() for c in self._connections.values()))
 
     async def disconnect_all(self) -> None:
+        self._check_if_alive()
         await self._disconnect_all()
 
     async def close(self) -> None:


Test patch:
diff --git a/tests/hikari/impl/test_voice.py b/tests/hikari/impl/test_voice.py
index be1e5c54..f4795457 100644
--- a/tests/hikari/impl/test_voice.py
+++ b/tests/hikari/impl/test_voice.py
@@ -69,9 +69,11 @@ async def test_disconnect(self, voice_client):
             snowflakes.Snowflake(123): mock_connection,
             snowflakes.Snowflake(5324): mock_connection_2,
         }
+        voice_client._check_if_alive = mock.Mock()
 
         await voice_client.disconnect(123)
 
+        voice_client._check_if_alive.assert_called_once_with()
         mock_connection.disconnect.assert_awaited_once_with()
         mock_connection_2.disconnect.assert_not_called()
 
@@ -101,18 +103,22 @@ async def test__disconnect_all(self, voice_client):
     @pytest.mark.asyncio()
     async def test_disconnect_all(self, voice_client):
         voice_client._disconnect_all = mock.AsyncMock()
+        voice_client._check_if_alive = mock.Mock()
 
         await voice_client.disconnect_all()
 
+        voice_client._check_if_alive.assert_called_once_with()
         voice_client._disconnect_all.assert_awaited_once_with()
 
     @pytest.mark.asyncio()
     async def test_close(self, voice_client, mock_app):
         voice_client._disconnect_all = mock.AsyncMock()
         voice_client._connections = {123: None}
+        voice_client._check_if_alive = mock.Mock()
 
         await voice_client.close()
 
+        voice_client._check_if_alive.assert_called_once_with()
         mock_app.event_manager.unsubscribe.assert_called_once_with(
             voice_events.VoiceEvent, voice_client._on_voice_event
         )
@@ -146,9 +152,11 @@ async def test_connect_to(self, voice_client, mock_app):
         mock_app.shard_count = 42
         mock_app.shards = {0: mock_shard}
         mock_connection_type = mock.AsyncMock()
+        voice_client._check_if_alive = mock.Mock()
 
         result = await voice_client.connect_to(123, 4532, mock_connection_type, deaf=False, mute=True)
 
+        voice_client._check_if_alive.assert_called_once_with()
         mock_app.event_manager.wait_for.assert_has_awaits(
             [
                 mock.call(