]> granicus.if.org Git - php/commitdiff
Avoid spurious failures of MySQL INSERT packet overflow test
authorAlex Dowad <alexinbeijing@gmail.com>
Wed, 22 Apr 2020 18:52:16 +0000 (20:52 +0200)
committerMáté Kocsis <kocsismate@woohoolabs.com>
Fri, 1 May 2020 10:25:42 +0000 (12:25 +0200)
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

ext/mysqli/tests/mysqli_insert_packet_overflow.phpt

index fc6b6a3ad7c89e0b928e410b89747fbfe67b02d8..69f781f48a10b49e2a47d84d0224bc4fe71973e2 100644 (file)
@@ -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));
+    }
+
+    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 test(col_blob) VALUES ('";
+    $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--
-<?php
-       require_once("clean_table.inc");
-?>
 --EXPECT--
 done!