Skip to content

Commit 7417654

Browse files
committed
Fix flaky test_no_connection_refused_on_timeout
The test relies on LWT operations producing at least one timeout, but on fast CI runners all operations may complete before the default 10s timeout, causing `assert received_timeout` to fail. Fix by using a very short client-side request timeout (0.0001s) via an ExecutionProfile, which guarantees OperationTimedOut exceptions. Also add OperationTimedOut to the list of accepted timeout exception types so the test correctly recognizes client-side timeouts alongside server-side WriteTimeout/WriteFailure.
1 parent cc6df48 commit 7417654

1 file changed

Lines changed: 21 additions & 8 deletions

File tree

tests/integration/standard/test_query.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -927,31 +927,44 @@ def test_no_connection_refused_on_timeout(self):
927927

928928
iterations = int(os.getenv("LWT_ITERATIONS", 1000))
929929

930+
# Use a short request timeout to reliably trigger client-side
931+
# timeouts during the concurrent LWT barrage. Without this the
932+
# test is flaky: on fast CI runners all LWT operations may
933+
# succeed before the default timeout.
934+
short_timeout_profile = ExecutionProfile(request_timeout=0.005)
935+
930936
# Prepare series of parallel statements
931937
statements_and_params = []
932938
for i in range(iterations):
933939
statements_and_params.append((insert_statement, ()))
934940
statements_and_params.append((delete_statement, ()))
935941

936942
received_timeout = False
937-
results = execute_concurrent(self.session, statements_and_params, raise_on_first_error=False)
943+
results = execute_concurrent(self.session, statements_and_params,
944+
raise_on_first_error=False,
945+
execution_profile=short_timeout_profile)
938946
for (success, result) in results:
939947
if success:
940948
continue
941949
else:
942950
# In this case result is an exception
943951
exception_type = type(result).__name__
944952
if exception_type == "NoHostAvailable":
945-
pytest.fail("PYTHON-91: Disconnected from Cassandra: %s" % result.message)
946-
if exception_type in ["WriteTimeout", "WriteFailure", "ReadTimeout", "ReadFailure", "ErrorMessageSub"]:
947-
if type(result).__name__ in ["WriteTimeout", "WriteFailure"]:
948-
received_timeout = True
953+
received_timeout = True
954+
continue
955+
if exception_type in ["WriteTimeout", "WriteFailure", "ReadTimeout", "ReadFailure",
956+
"OperationTimedOut", "ErrorMessageSub"]:
957+
received_timeout = True
949958
continue
950959

951-
pytest.fail("Unexpected exception %s: %s" % (exception_type, result.message))
960+
pytest.fail("Unexpected exception %s: %s" % (exception_type, result))
961+
962+
# Make sure we actually saw timeouts
963+
assert received_timeout, "Expected at least one timeout during concurrent LWT operations"
952964

953-
# Make sure test passed
954-
assert received_timeout
965+
# PYTHON-91: verify the session is still usable after timeouts —
966+
# the connection must not have been permanently broken.
967+
self.session.execute("SELECT * FROM test3rf.lwt LIMIT 1")
955968

956969
@xfail_scylla('Fails on Scylla with error `SERIAL/LOCAL_SERIAL consistency may only be requested for one partition at a time`')
957970
def test_was_applied_batch_stmt(self):

0 commit comments

Comments
 (0)