'Test for PYTHON-91 "Connection closed after LWT timeout"
Verifies that connection to the cluster is not shut down when timeout occurs.
Number of iterations can be specified with LWT_ITERATIONS environment variable.
Default value is 1000'

def test_no_connection_refused_on_timeout(self):

    insert_statement = self.session.prepare('INSERT    INTO    test3rf.lwt    (k,    v)    VALUES    (0,    0)    IF    NOT    EXISTS')
    delete_statement = self.session.prepare('DELETE    FROM    test3rf.lwt    WHERE    k    =    0    IF    EXISTS')
    iterations = int(os.getenv('LWT_ITERATIONS', 1000))
    statements_and_params = []
    for i in range(iterations):
        statements_and_params.append((insert_statement, ()))
        statements_and_params.append((delete_statement, ()))
    received_timeout = False
    results = execute_concurrent(self.session, statements_and_params, raise_on_first_error=False)
    for (success, result) in results:
        if success:
            continue
        else:
            if (type(result).__name__ == 'NoHostAvailable'):
                self.fail(('PYTHON-91:    Disconnected    from    Cassandra:    %s' % result.message))
            if (type(result).__name__ == 'WriteTimeout'):
                received_timeout = True
                continue
            if (type(result).__name__ == 'WriteFailure'):
                received_timeout = True
                continue
            if (type(result).__name__ == 'ReadTimeout'):
                continue
            if (type(result).__name__ == 'ReadFailure'):
                continue
            self.fail(('Unexpected    exception    %s:    %s' % (type(result).__name__, result.message)))
    self.assertTrue(received_timeout)
