Skip to content

Commit 7b32d17

Browse files
alexdowadkocsismate
authored andcommitted
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
1 parent 86ed93c commit 7b32d17

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

ext/mysqli/tests/mysqli_insert_packet_overflow.phpt

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,15 @@ memory_limit=256M
7171
printf("[011] Failed to change max_allowed_packet");
7272
}
7373

74-
if (!mysqli_query($link, "CREATE TABLE test(col_blob LONGBLOB) ENGINE=" . $engine))
75-
printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
74+
$table_name = 'test__mysqli_insert_packet_overflow';
75+
if (!mysqli_query($link, "DROP TABLE IF EXISTS {$table_name}")) {
76+
printf("[012] Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
77+
}
78+
79+
if (!mysqli_query($link, "CREATE TABLE {$table_name}(col_blob LONGBLOB) ENGINE=" . $engine))
80+
printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
7681

77-
$query_prefix = "INSERT INTO test(col_blob) VALUES ('";
82+
$query_prefix = "INSERT INTO {$table_name}(col_blob) VALUES ('";
7883
$query_postfix = "')";
7984
$query_len = strlen($query_prefix) + strlen($query_postfix);
8085
$com_query_len = 2;
@@ -84,16 +89,16 @@ memory_limit=256M
8489
$query = sprintf("%s%s%s", $query_prefix, $blob, $query_postfix);
8590

8691
if (!mysqli_query($link, $query))
87-
printf("[013] max_allowed_packet = %d, strlen(query) = %d, [%d] %s\n", $max_allowed_packet, strlen($query), mysqli_errno($link), mysqli_error($link));
92+
printf("[014] max_allowed_packet = %d, strlen(query) = %d, [%d] %s\n", $max_allowed_packet, strlen($query), mysqli_errno($link), mysqli_error($link));
8893

89-
if (!$res = mysqli_query($link, "SELECT col_blob FROM test"))
90-
printf("[014] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
94+
if (!$res = mysqli_query($link, "SELECT col_blob FROM {$table_name}"))
95+
printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
9196

9297
if (!$row = mysqli_fetch_assoc($res)) {
93-
printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
98+
printf("[016] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
9499
} else {
95100
if ($row['col_blob'] != $blob) {
96-
printf("[016] Blob seems wrong, dumping data\n");
101+
printf("[017] Blob seems wrong, dumping data\n");
97102
var_dump(strlen($row['col_blob']));
98103
var_dump(strlen($blob));
99104
}
@@ -102,15 +107,11 @@ memory_limit=256M
102107

103108
if (!mysqli_query($link, "SET GLOBAL max_allowed_packet = " . $org_max_allowed_packet))
104109
if (1227 != mysqli_errno($link))
105-
printf("[017] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
110+
printf("[018] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
106111

107112
mysqli_close($link);
108113

109114
print "done!";
110115
?>
111-
--CLEAN--
112-
<?php
113-
require_once("clean_table.inc");
114-
?>
115116
--EXPECT--
116117
done!

0 commit comments

Comments
 (0)