From 7b32d176d2ef6f144083f1df15f5b15500f40447 Mon Sep 17 00:00:00 2001 From: Alex Dowad Date: Wed, 22 Apr 2020 20:52:16 +0200 Subject: [PATCH] Avoid spurious failures of MySQL INSERT packet overflow test This test creates a MySQL table called 'test'. In several cases, I have seen a spurious test failure (in CI) with an error message saying: "table 'test' already exists". It may be that another test had used a table with the same name and not cleaned it out correctly. Or maybe we have multiple tests running in parallel in some CI environments, or the same test DB being used for multiple runs of the test suite. In any case, change the table name so it is exclusive to this test case only. Also, if the test table exists at the beginning of the test, drop it. Closes GH-5479 --- .../tests/mysqli_insert_packet_overflow.phpt | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/ext/mysqli/tests/mysqli_insert_packet_overflow.phpt b/ext/mysqli/tests/mysqli_insert_packet_overflow.phpt index fc6b6a3ad7c..69f781f48a1 100644 --- a/ext/mysqli/tests/mysqli_insert_packet_overflow.phpt +++ b/ext/mysqli/tests/mysqli_insert_packet_overflow.phpt @@ -71,10 +71,15 @@ memory_limit=256M printf("[011] Failed to change max_allowed_packet"); } - if (!mysqli_query($link, "CREATE TABLE test(col_blob LONGBLOB) ENGINE=" . $engine)) - printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + $table_name = 'test__mysqli_insert_packet_overflow'; + if (!mysqli_query($link, "DROP TABLE IF EXISTS {$table_name}")) { + printf("[012] Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + } - $query_prefix = "INSERT INTO test(col_blob) VALUES ('"; + if (!mysqli_query($link, "CREATE TABLE {$table_name}(col_blob LONGBLOB) ENGINE=" . $engine)) + printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + + $query_prefix = "INSERT INTO {$table_name}(col_blob) VALUES ('"; $query_postfix = "')"; $query_len = strlen($query_prefix) + strlen($query_postfix); $com_query_len = 2; @@ -84,16 +89,16 @@ memory_limit=256M $query = sprintf("%s%s%s", $query_prefix, $blob, $query_postfix); if (!mysqli_query($link, $query)) - printf("[013] max_allowed_packet = %d, strlen(query) = %d, [%d] %s\n", $max_allowed_packet, strlen($query), mysqli_errno($link), mysqli_error($link)); + printf("[014] max_allowed_packet = %d, strlen(query) = %d, [%d] %s\n", $max_allowed_packet, strlen($query), mysqli_errno($link), mysqli_error($link)); - if (!$res = mysqli_query($link, "SELECT col_blob FROM test")) - printf("[014] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + if (!$res = mysqli_query($link, "SELECT col_blob FROM {$table_name}")) + printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); if (!$row = mysqli_fetch_assoc($res)) { - printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + printf("[016] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); } else { if ($row['col_blob'] != $blob) { - printf("[016] Blob seems wrong, dumping data\n"); + printf("[017] Blob seems wrong, dumping data\n"); var_dump(strlen($row['col_blob'])); var_dump(strlen($blob)); } @@ -102,15 +107,11 @@ memory_limit=256M if (!mysqli_query($link, "SET GLOBAL max_allowed_packet = " . $org_max_allowed_packet)) if (1227 != mysqli_errno($link)) - printf("[017] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); + printf("[018] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); mysqli_close($link); print "done!"; ?> ---CLEAN-- - --EXPECT-- done!