async def test_broadcast_connection_error(lobbyconnection: LobbyConnection, player_factory): player = lobbyconnection.player player.lobby_connection = lobbyconnection player.id = 1 tuna = player_factory("Tuna", player_id=55, with_lobby_connection=True) tuna.lobby_connection.write_warning.side_effect = DisconnectedError( "Some error") data = {player.id: player, tuna.id: tuna} lobbyconnection.player_service.__iter__.side_effect = data.values( ).__iter__ lobbyconnection.write_warning = Mock() # This should not leak any exceptions await lobbyconnection.on_message_received({ "command": "admin", "action": "broadcast", "message": "This is a test message" }) player.lobby_connection.write_warning.assert_called_with( "This is a test message")
async def test_broadcast_during_disconnect(lobbyconnection: LobbyConnection, player_factory): player = lobbyconnection.player player.lobby_connection = lobbyconnection player.id = 1 # To simulate when a player has been recently disconnected so that they # still appear in the player_service list, but their lobby_connection # object has already been destroyed tuna = player_factory("Tuna", player_id=55, with_lobby_connection=False) data = {player.id: player, tuna.id: tuna} lobbyconnection.player_service.__iter__.side_effect = data.values( ).__iter__ lobbyconnection.write_warning = Mock() # This should not leak any exceptions await lobbyconnection.on_message_received({ "command": "admin", "action": "broadcast", "message": "This is a test message" }) player.lobby_connection.write_warning.assert_called_with( "This is a test message")