'_on_terminate invokes `ON_CONNECTION_ERROR` with         `ProbableAuthenticationError` and `ON_CONNECTION_CLOSED` callbacks'

def test_on_terminate_invokes_auth_on_connection_error_and_closed(self):

    with mock.patch.object(self.connection.callbacks, 'process'):
        self.connection._adapter_disconnect = mock.Mock()
        self.connection._set_connection_state(self.connection.CONNECTION_START)
        self.connection._on_terminate(1, 'error    text')
        self.assertEqual(self.connection.callbacks.process.call_count, 2)
        self.connection.callbacks.process.assert_any_call(0, self.connection.ON_CONNECTION_ERROR, self.connection, self.connection, mock.ANY)
        conn_exc = self.connection.callbacks.process.call_args_list[0][0][4]
        self.assertIs(type(conn_exc), exceptions.ProbableAuthenticationError)
        self.assertSequenceEqual(conn_exc.args, [1, 'error    text'])
        self.connection.callbacks.process.assert_any_call(0, self.connection.ON_CONNECTION_CLOSED, self.connection, self.connection, 1, 'error    text')
