diff options
| author | Ondřej Surý <ondrej@sury.org> | 2012-01-11 15:43:42 +0100 |
|---|---|---|
| committer | Ondřej Surý <ondrej@sury.org> | 2012-01-11 15:43:42 +0100 |
| commit | 8f1428d29ef91d74b4d272af171675f2971eb15b (patch) | |
| tree | a1f4f4d7dc5bfe8096806dd5c5266634e19fa07a /ext/mysql/tests | |
| parent | c6e4182351e0173fe58de141e143aac2eacf5efe (diff) | |
| download | php-8f1428d29ef91d74b4d272af171675f2971eb15b.tar.gz | |
Imported Upstream version 5.3.9upstream/5.3.9
Diffstat (limited to 'ext/mysql/tests')
| -rwxr-xr-x | ext/mysql/tests/001.phpt | 5 | ||||
| -rw-r--r-- | ext/mysql/tests/bug53649.phpt | 36 | ||||
| -rw-r--r-- | ext/mysql/tests/bug55473.phpt | 79 | ||||
| -rwxr-xr-x | ext/mysql/tests/connect.inc | 5 | ||||
| -rw-r--r-- | ext/mysql/tests/mysql_affected_rows.phpt | 2 | ||||
| -rw-r--r-- | ext/mysql/tests/mysql_connect.phpt | 5 | ||||
| -rw-r--r-- | ext/mysql/tests/mysql_insert_id.phpt | 2 | ||||
| -rw-r--r-- | ext/mysql/tests/mysql_max_links.phpt | 1 | ||||
| -rw-r--r-- | ext/mysql/tests/mysql_num_rows.phpt | 17 | ||||
| -rwxr-xr-x | ext/mysql/tests/mysql_pconn_kill.phpt | 4 | ||||
| -rw-r--r-- | ext/mysql/tests/mysql_query_load_data_openbasedir.phpt | 13 | ||||
| -rw-r--r-- | ext/mysql/tests/mysql_sql_safe_mode.phpt | 1 | ||||
| -rw-r--r-- | ext/mysql/tests/setupdefault.inc | 10 | ||||
| -rwxr-xr-x | ext/mysql/tests/skipifdefaultconnectfailure.inc | 11 |
14 files changed, 161 insertions, 30 deletions
diff --git a/ext/mysql/tests/001.phpt b/ext/mysql/tests/001.phpt index 6f2e284de..72b661477 100755 --- a/ext/mysql/tests/001.phpt +++ b/ext/mysql/tests/001.phpt @@ -1,7 +1,10 @@ --TEST-- mysql connect --SKIPIF-- -<?php include 'skipif.inc'; ?> +<?php +require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); +?> --FILE-- <?php require_once('connect.inc'); diff --git a/ext/mysql/tests/bug53649.phpt b/ext/mysql/tests/bug53649.phpt index 126f34b73..70bf9bed3 100644 --- a/ext/mysql/tests/bug53649.phpt +++ b/ext/mysql/tests/bug53649.phpt @@ -4,28 +4,46 @@ Bug #53649 (mysql_query with "load data" unable to save result set) <?php
require_once('skipif.inc');
require_once('skipifconnectfailure.inc');
+
+if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket)) {
+ die(sprintf("skip Connect failed, [%d] %s\n", mysqlerrno(), mysqli_error()));
+}
+
+if (!mysql_query("DROP TABLE IF EXISTS test", $link) ||
+ !mysql_query("CREATE TABLE test (dump1 INT UNSIGNED NOT NULL PRIMARY KEY) ENGINE=" . $engine, $link))
+ die(sprintf("skip [%d] %s\n", mysql_errno($link), mysql_error($link)));
+
+if (false === file_put_contents('bug53649.data', "1\n2\n3\n"))
+ die(sprintf("skip Failed to create data file\n"));
+
+if (!mysql_query("LOAD DATA LOCAL INFILE 'bug53649.data' INTO TABLE test", $link) &&
+ 1148 == mysql_errno($link))
+ die("skip LOAD DATA LOAD INFILE not allowed\n");
?>
--FILE--
<?php
require_once("connect.inc");
if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket)) {
- printf("[001] Connect failed, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
+ printf("[001] Connect failed, [%d] %s\n", mysqlerrno(), mysqli_error());
}
- if (!mysql_query("DROP TABLE IF EXISTS tlocaldata", $link)) {
- printf("[002] [%d] %s\n", $link->errno, $link->error);
+ if (!mysql_query("DROP TABLE IF EXISTS test", $link)) {
+ printf("[002] [%d] %s\n", mysql_errno($link), mysql_error($link));
}
- if (!mysql_query("CREATE TABLE tlocaldata (dump1 INT UNSIGNED NOT NULL PRIMARY KEY) ENGINE=" . $engine, $link)) {
- printf("[003] [%d] %s\n", $link->errno, $link->error);
+ if (!mysql_query("CREATE TABLE test (dump1 INT UNSIGNED NOT NULL PRIMARY KEY) ENGINE=" . $engine, $link)) {
+ printf("[003] [%d] %s\n", mysql_errno($link), mysql_error($link));
}
- file_put_contents('bug53649.data', "1\n2\n3\n");
+ if (false === file_put_contents('bug53649.data', "1\n2\n3\n"))
+ printf("[004] Failed to create data file\n");
- mysql_query("SELECT 1 FROM DUAL", $link);
+ if (!mysql_query("SELECT 1 FROM DUAL", $link))
+ printf("[005] [%d] %s\n", mysql_errno($link), mysql_error($link));
- if (!mysql_query("LOAD DATA LOCAL INFILE 'bug53649.data' INTO TABLE tlocaldata", $link)) {
+ if (!mysql_query("LOAD DATA LOCAL INFILE 'bug53649.data' INTO TABLE test", $link)) {
+ printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link));
echo "bug";
} else {
echo "done";
@@ -41,7 +59,7 @@ if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket)) { $host, $user, $db, $port, $socket);
}
-if (!mysql_query($link, 'DROP TABLE IF EXISTS tlocaldata', $link)) {
+if (!mysql_query($link, 'DROP TABLE IF EXISTS test', $link)) {
printf("[clean] Failed to drop old test table: [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
diff --git a/ext/mysql/tests/bug55473.phpt b/ext/mysql/tests/bug55473.phpt new file mode 100644 index 000000000..df584bdef --- /dev/null +++ b/ext/mysql/tests/bug55473.phpt @@ -0,0 +1,79 @@ +--TEST-- +Bug #5547 (mysql_pconnect leaks file descriptors on reconnect) +--SKIPIF-- +<?php +require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); +if (defined('PHP_WINDOWS_VERSION_MAJOR')) { + die("skip Test doesn't work on Windows"); +} + +if (!($output = @exec("lsof -np " . getmypid()))) + die("skip Test can't find command line tool lsof"); +?> +--INI-- +mysql.max_persistent=30 +mysql.allow_persistent=1 +--FILE-- +<?php + include "connect.inc"; + + $tmp = NULL; + $link = NULL; + + if ($socket) + $host = sprintf("%s:%s", $host, $socket); + else if ($port) + $host = sprintf("%s:%s", $host, $port); + + function connect($host, $user, $passwd) { + $conn = mysql_pconnect($host, $user, $passwd); + + if (!$conn) + die(sprintf("[001] %s\n", mysql_error())); + + if (!mysql_query("set wait_timeout=1", $conn)) + printf("[002] [%d] %s\n", mysql_errno($conn), mysql_error($conn)); + + return $conn; + } + + $conn = connect($host, $user, $passwd); + $opened_files = -1; + + for ($i = 0; $i < 4; $i++) { + /* wait while mysql closes connection */ + sleep(3); + + if (!mysql_ping($conn)) { + printf("[003] reconnect %d\n", $i); + $conn = connect($host, $user, $passwd); + } + + $r = mysql_query('select 1', $conn); + if (!$r) + printf("[004] [%d] %s\n", mysql_errno($conn), mysql_error($conn)); + + + if ($opened_files == -1) { + $opened_files = trim(exec("lsof -np " . getmypid() . " | wc -l")); + printf("[005] Setting openened files...\n"); + } else if (($tmp = trim(exec("lsof -np " . getmypid() . " | wc -l"))) != $opened_files) { + printf("[006] [%d] different number of opened_files : expected %d, got %d", $i, $opened_files, $tmp); + } else { + printf("[007] Opened files as expected\n"); + } + } + + print "done!"; +?> +--EXPECTF-- +[003] reconnect 0 +[005] Setting openened files... +[003] reconnect 1 +[007] Opened files as expected +[003] reconnect 2 +[007] Opened files as expected +[003] reconnect 3 +[007] Opened files as expected +done!
\ No newline at end of file diff --git a/ext/mysql/tests/connect.inc b/ext/mysql/tests/connect.inc index 97fed4214..0df5bc3aa 100755 --- a/ext/mysql/tests/connect.inc +++ b/ext/mysql/tests/connect.inc @@ -64,13 +64,14 @@ $host = getenv("MYSQL_TEST_HOST") ? getenv("MYSQL_TEST_HOST") : "localhost"; $port = getenv("MYSQL_TEST_PORT") ? getenv("MYSQL_TEST_PORT") : 3306; $user = getenv("MYSQL_TEST_USER") ? getenv("MYSQL_TEST_USER") : "root"; $passwd = getenv("MYSQL_TEST_PASSWD") ? getenv("MYSQL_TEST_PASSWD") : ""; + $db = getenv("MYSQL_TEST_DB") ? getenv("MYSQL_TEST_DB") : "test"; $engine = getenv("MYSQL_TEST_ENGINE") ? getenv("MYSQL_TEST_ENGINE") : "MyISAM"; $socket = getenv("MYSQL_TEST_SOCKET") ? getenv("MYSQL_TEST_SOCKET") : null; $skip_on_connect_failure = getenv("MYSQL_TEST_SKIP_CONNECT_FAILURE") ? getenv("MYSQL_TEST_SKIP_CONNECT_FAILURE") : true; $connect_flags = getenv("MYSQL_TEST_CONNECT_FLAGS") ? (int)getenv("MYSQL_TEST_CONNECT_FLAGS") : 0; if ($socket) { - ini_set('mysql.default_user', $socket); + ini_set('mysql.default_socket', $socket); } /* Development setting: test experimal features and/or feature requests that never worked before? */ $TEST_EXPERIMENTAL = (in_array(getenv("MYSQL_TEST_EXPERIMENTAL"), array(0, 1))) ? @@ -78,4 +79,4 @@ $TEST_EXPERIMENTAL = (in_array(getenv("MYSQL_TEST_EXPERIMENTAL"), array(0, 1))) false; $IS_MYSQLND = stristr(mysql_get_client_info(), "mysqlnd"); -?>
\ No newline at end of file +?> diff --git a/ext/mysql/tests/mysql_affected_rows.phpt b/ext/mysql/tests/mysql_affected_rows.phpt index ce16a7748..145e1f5c0 100644 --- a/ext/mysql/tests/mysql_affected_rows.phpt +++ b/ext/mysql/tests/mysql_affected_rows.phpt @@ -4,11 +4,11 @@ mysql_affected_rows() <?php require_once('skipif.inc'); require_once('skipifconnectfailure.inc'); -require_once('skipifdefaultconnectfailure.inc'); ?> --FILE-- <?php include_once("connect.inc"); +include_once('setupdefault.inc'); $tmp = NULL; $link = NULL; diff --git a/ext/mysql/tests/mysql_connect.phpt b/ext/mysql/tests/mysql_connect.phpt index 773264e5a..715824804 100644 --- a/ext/mysql/tests/mysql_connect.phpt +++ b/ext/mysql/tests/mysql_connect.phpt @@ -1,7 +1,10 @@ --TEST-- mysql_connect() --SKIPIF-- -<?php require_once('skipif.inc'); ?> +<?php +require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); +?> --FILE-- <?php include_once "connect.inc"; diff --git a/ext/mysql/tests/mysql_insert_id.phpt b/ext/mysql/tests/mysql_insert_id.phpt index 678245c2c..460d9f3f4 100644 --- a/ext/mysql/tests/mysql_insert_id.phpt +++ b/ext/mysql/tests/mysql_insert_id.phpt @@ -4,11 +4,11 @@ mysql_insert_id() <?php require_once('skipif.inc'); require_once('skipifconnectfailure.inc'); -require_once('skipifdefaultconnectfailure.inc'); ?> --FILE-- <?php include "connect.inc"; +include 'setupdefault.inc'; $tmp = NULL; $link = NULL; diff --git a/ext/mysql/tests/mysql_max_links.phpt b/ext/mysql/tests/mysql_max_links.phpt index fbe3ae003..52ecd0ac0 100644 --- a/ext/mysql/tests/mysql_max_links.phpt +++ b/ext/mysql/tests/mysql_max_links.phpt @@ -3,6 +3,7 @@ mysql_[p]connect() - max_links/max_persistent --SKIPIF-- <?php require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); ?> --INI-- mysql.max_links=2 diff --git a/ext/mysql/tests/mysql_num_rows.phpt b/ext/mysql/tests/mysql_num_rows.phpt index 1f68b4d60..0f538c4a2 100644 --- a/ext/mysql/tests/mysql_num_rows.phpt +++ b/ext/mysql/tests/mysql_num_rows.phpt @@ -54,6 +54,23 @@ if ($res = mysql_query('SELECT COUNT(id) AS num FROM test', $link)) { printf("[030] [%d] %s\n", mysql_errno($link), mysql_error($link)); } +if ($res = mysql_unbuffered_query('SELECT id, label FROM test')) { + + if (0 != mysql_num_rows($res)) + printf("[032] Expecting 0 rows got %d\n", mysql_num_rows($res)); + + $rows = 0; + while ($row = mysql_fetch_assoc($res)) + $rows++; + + if ($rows != mysql_num_rows($res)) + printf("[033] Expecting %d rows got %d\n", $rows, mysql_num_rows($res)); + + mysql_free_result($res); +} else { + printf("[034] [%d] %s\n", mysql_errno($link), mysql_error($link)); +} + mysql_close($link); print "done!"; ?> diff --git a/ext/mysql/tests/mysql_pconn_kill.phpt b/ext/mysql/tests/mysql_pconn_kill.phpt index 8543e39d6..20dfbe9a1 100755 --- a/ext/mysql/tests/mysql_pconn_kill.phpt +++ b/ext/mysql/tests/mysql_pconn_kill.phpt @@ -64,7 +64,9 @@ mysql.max_persistent=2 mysql_close($plink); - if (!($plink = mysql_pconnect($myhost, $user, $passwd))) + /* mysql_pconnect cound generate a warning when linked against mysqlnd + PHP Warning: mysql_pconnect(): MySQL server has gone away */ + if (!($plink = @mysql_pconnect($myhost, $user, $passwd))) printf("[009] Cannot create new persistent connection, [%d] %s\n", mysql_errno(), mysql_error()); mysql_select_db($db, $plink); diff --git a/ext/mysql/tests/mysql_query_load_data_openbasedir.phpt b/ext/mysql/tests/mysql_query_load_data_openbasedir.phpt index ff62f4227..c2685a572 100644 --- a/ext/mysql/tests/mysql_query_load_data_openbasedir.phpt +++ b/ext/mysql/tests/mysql_query_load_data_openbasedir.phpt @@ -2,9 +2,15 @@ LOAD DATA INFILE - open_basedir --SKIPIF-- <?php -require_once('skipif.inc'); -require_once('skipifconnectfailure.inc'); -require_once("connect.inc"); +@include_once("connect.inc"); + +if (!isset($db)) { + die("skip open_basedir setting prevents inclusing of required files"); +} + +include_once('skipif.inc'); +include_once('skipifconnectfailure.inc'); + if (!$IS_MYSQLND) die("skip mysqlnd only, libmysql does not know about open_basedir restrictions"); @@ -30,6 +36,7 @@ open_basedir="." --FILE-- <?php @include_once("connect.inc"); + if (!isset($db)) { // run-tests, I love you for not allowing me to set ini settings dynamically print "[006] [1148] The used command is not allowed with this MySQL version diff --git a/ext/mysql/tests/mysql_sql_safe_mode.phpt b/ext/mysql/tests/mysql_sql_safe_mode.phpt index 6c652fb57..4d8ca92e4 100644 --- a/ext/mysql/tests/mysql_sql_safe_mode.phpt +++ b/ext/mysql/tests/mysql_sql_safe_mode.phpt @@ -3,6 +3,7 @@ mysql_[p]connect() - safe_mode --SKIPIF-- <?php require_once('skipif.inc'); +require_once('skipifconnectfailure.inc'); $link = @mysql_connect("", "", "", true); if ($link) die("skip Test cannot be run if annonymous connections are allowed"); diff --git a/ext/mysql/tests/setupdefault.inc b/ext/mysql/tests/setupdefault.inc new file mode 100644 index 000000000..6d25c2084 --- /dev/null +++ b/ext/mysql/tests/setupdefault.inc @@ -0,0 +1,10 @@ +<?php + +// copy variables from connect.inc into mysql default connection ini settings, so that implicit mysql_connect() behaviour can be tested where needed +// must be loaded AFTER connect.inc + +ini_set('mysql.default_host', $host); +ini_set('mysql.default_user', $user); +ini_set('mysql.default_password', $passwd); + +?> diff --git a/ext/mysql/tests/skipifdefaultconnectfailure.inc b/ext/mysql/tests/skipifdefaultconnectfailure.inc deleted file mode 100755 index 99f390515..000000000 --- a/ext/mysql/tests/skipifdefaultconnectfailure.inc +++ /dev/null @@ -1,11 +0,0 @@ -<?php -if ($skip_on_connect_failure) { - if (!$link = @mysql_connect()) - die(sprintf("skip Can't connect to MySQL Server with default credentials - [%d] %s", mysql_errno(), mysql_error())); - - if (!@mysql_select_db($db, $link)) - die(sprintf("skip Can't connect to MySQL Server with default credentials - [%d] %s", mysql_errno(), mysql_error())); - - mysql_close($link); -} -?> |
