From 13a43e2ffe7cc650503acf75675dbfeda5bf7aa8 Mon Sep 17 00:00:00 2001 From: Rene Cannao Date: Tue, 14 Apr 2026 10:50:29 +0000 Subject: [PATCH] fix(test/tap): revert two semantic regressions from cleanup commits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two recent "cleanup" commits on this branch silently changed test behavior and caused the tests to fail under myrun2. 1) kill_connection2-t.cpp (regressed in 3f0cd6a0c): The "cleanup - replace NULL with nullptr, convert loops to range-based" commit flipped one assertion from ok(rc == 0, ...) to ok(rc != 0, ...) on the first DO 1 batch after a 12s sleep. With mysql-max_transaction_time=17000 (17s), the connection is still alive at 12s by design — ProxySQL only kills it at ~18s. The original test correctly expected rc == 0 there; the second DO 1 batch (after +12s = 24s total) continues to correctly expect rc != 0. 2) max_connections_ff-t.cpp (regressed in da655099e): The "static analysis narrowing conversions" commit introduced an integer overflow by wrapping a chrono::nanoseconds count in static_cast(). For the 8000ms test the elapsed time is ~8e9 ns, which overflows int32 (max ~2.147e9) and wraps negative, producing "Waited: -0.589502" and a failed assertion. The 2000ms test happened to fit under 2.147e9 ns and kept passing, hiding the bug. Use static_cast for the nanoseconds count, and drop the unnecessary int casts on connect_timeout / poll_timeout — those are already long, so long / 1000.0 is a valid double. --- test/tap/tests/kill_connection2-t.cpp | 2 +- test/tap/tests/max_connections_ff-t.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/tap/tests/kill_connection2-t.cpp b/test/tap/tests/kill_connection2-t.cpp index 1e6f0d947..06d6150fa 100644 --- a/test/tap/tests/kill_connection2-t.cpp +++ b/test/tap/tests/kill_connection2-t.cpp @@ -201,7 +201,7 @@ int main(int argc, char** argv) { for (auto& conn : conns) { MYSQL * mysql = conn; int rc = run_q(mysql, "DO 1"); - ok(rc != 0, (rc == 0 ? "Connection still alive" : "Connection killed")); + ok(rc == 0, (rc == 0 ? "Connection still alive" : "Connection killed")); } diag("Sleeping for 12 seconds"); diff --git a/test/tap/tests/max_connections_ff-t.cpp b/test/tap/tests/max_connections_ff-t.cpp index aa99e7f8b..522f5dcf4 100644 --- a/test/tap/tests/max_connections_ff-t.cpp +++ b/test/tap/tests/max_connections_ff-t.cpp @@ -408,13 +408,13 @@ int test_ff_sess_exceeds_max_conns(const CommandLine& cl, MYSQL* proxy_admin, lo hrc::time_point end = hrc::now(); duration = end - start; - double duration_s = static_cast(duration.count()) / pow(10,9); + double duration_s = static_cast(duration.count()) / pow(10,9); diag("Query completed - Error: %d, ErrMsg: %s", m_errno, m_error); diag("Time waited: %lf seconds", duration_s); - const double srv_conn_to_s = static_cast(connect_timeout) / 1000.0; - const double poll_to_s = static_cast(poll_timeout) / 1000.0; + const double srv_conn_to_s = connect_timeout / 1000.0; + const double poll_to_s = poll_timeout / 1000.0; const double grace = 500 / 1000.0; ok(