def test_using_etf_is_unsupported(self, http_settings, proxy_settings): with pytest.raises(NotImplementedError, match="Unsupported gateway data format: etf"): shard.GatewayShardImpl( event_consumer=mock.Mock(), http_settings=http_settings, proxy_settings=proxy_settings, token=mock.Mock(), url="wss://erlpack-is-broken-lol.discord.meh", data_format="etf", compression=True, )
def test__init__sets_url_is_correct_json(self, compression, expect, http_settings, proxy_settings): g = shard.GatewayShardImpl( event_consumer=mock.Mock(), http_settings=http_settings, proxy_settings=proxy_settings, url="wss://gaytewhuy.discord.meh", data_format="json", compression=compression, token="12345", ) assert g._url == f"wss://gaytewhuy.discord.meh?{expect}"
async def _start_one_shard( self, activity: typing.Optional[presences.Activity], afk: bool, idle_since: typing.Optional[datetime.datetime], status: presences.Status, large_threshold: int, shard_id: int, shard_count: int, url: str, ) -> shard_impl.GatewayShardImpl: new_shard = shard_impl.GatewayShardImpl( event_consumer=self._raw_event_consumer, http_settings=self._http_settings, initial_activity=activity, initial_is_afk=afk, initial_idle_since=idle_since, initial_status=status, large_threshold=large_threshold, intents=self._intents, proxy_settings=self._proxy_settings, shard_id=shard_id, shard_count=shard_count, token=self._token, url=url, ) start = time.monotonic() await aio.first_completed(new_shard.start(), self._closing_event.wait()) end = time.monotonic() if new_shard.is_alive: _LOGGER.debug("Shard %s started successfully in %.1fms", shard_id, (end - start) * 1_000) return new_shard raise errors.GatewayError( f"shard {shard_id} shut down immediately when starting")