Merge pull request #764 from yitam/issue678
Added new tests for issue 678
This commit is contained in:
commit
dde0e23d69
|
@ -45,9 +45,7 @@ RUN export DEBIAN_FRONTEND=noninteractive && apt-get update && ACCEPT_EULA=Y apt
|
||||||
ENV PATH="/opt/mssql-tools/bin:${PATH}"
|
ENV PATH="/opt/mssql-tools/bin:${PATH}"
|
||||||
|
|
||||||
#install coveralls
|
#install coveralls
|
||||||
#RUN pip install --upgrade pip && pip install cpp-coveralls
|
RUN python -m pip install --upgrade pip && pip install cpp-coveralls
|
||||||
# TODO: Remove this workaround due to https://github.com/pypa/pip/issues/5240
|
|
||||||
RUN pip install --upgrade pip==9.0.3 && pip install cpp-coveralls
|
|
||||||
|
|
||||||
#Either Install git / download zip (One can see other strategies : https://ryanfb.github.io/etc/2015/07/29/git_strategies_for_docker.html )
|
#Either Install git / download zip (One can see other strategies : https://ryanfb.github.io/etc/2015/07/29/git_strategies_for_docker.html )
|
||||||
#One option is to get source from zip file of repository.
|
#One option is to get source from zip file of repository.
|
||||||
|
|
136
test/functional/pdo_sqlsrv/pdo_678_conn_resiliency_pooling.phpt
Normal file
136
test/functional/pdo_sqlsrv/pdo_678_conn_resiliency_pooling.phpt
Normal file
|
@ -0,0 +1,136 @@
|
||||||
|
--TEST--
|
||||||
|
GitHub issue #678 - Idle Connection Resiliency doesn't work with Connection Pooling
|
||||||
|
--DESCRIPTION--
|
||||||
|
Verifies that the issue has been fixed with ODBC 17.1
|
||||||
|
--ENV--
|
||||||
|
PHPT_EXEC=true
|
||||||
|
--SKIPIF--
|
||||||
|
<?php require('skipif_protocol_not_tcp.inc');
|
||||||
|
require('skipif_version_less_than_2k14.inc'); ?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
require_once("MsCommon_mid-refactor.inc");
|
||||||
|
|
||||||
|
function checkODBCVersion($conn)
|
||||||
|
{
|
||||||
|
$msodbcsql_ver = $conn->getAttribute(PDO::ATTR_CLIENT_VERSION)["DriverVer"];
|
||||||
|
$vers = explode(".", $msodbcsql_ver);
|
||||||
|
|
||||||
|
if ($vers[0] >= 17 && $vers[1] > 0){
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function breakConnection($conn, $conn_break)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$stmt1 = $conn->query("SELECT @@SPID");
|
||||||
|
$obj = $stmt1->fetch(PDO::FETCH_NUM);
|
||||||
|
$spid = $obj[0];
|
||||||
|
|
||||||
|
$stmt2 = $conn_break->prepare("KILL $spid");
|
||||||
|
$stmt2->execute();
|
||||||
|
sleep(1);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
print_r($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// create a connection for create the table and breaking other connections
|
||||||
|
$conn_break = connect();
|
||||||
|
|
||||||
|
if (! checkODBCVersion($conn_break)) {
|
||||||
|
echo "Done\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tableName = "test_connres";
|
||||||
|
dropTable($conn_break, $tableName);
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
$sql = "CREATE TABLE $tableName (c1 INT, c2 VARCHAR(40))";
|
||||||
|
$stmt = $conn_break->query($sql);
|
||||||
|
|
||||||
|
$sql = "INSERT INTO $tableName VALUES (?, ?)";
|
||||||
|
$stmt = $conn_break->prepare($sql);
|
||||||
|
for ($t = 200; $t < 209; $t++) {
|
||||||
|
$ts = substr(sha1($t), 0, 5);
|
||||||
|
$stmt->bindValue(1, $t);
|
||||||
|
$stmt->bindValue(2, $ts);
|
||||||
|
$stmt->execute();
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
echo "Could not connect.\n";
|
||||||
|
print_r($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// first connection
|
||||||
|
$connectionInfo = "ConnectRetryCount = 10; ConnectRetryInterval = 10; ConnectionPooling = 1;";
|
||||||
|
try {
|
||||||
|
$conn = connect($connectionInfo, array(), PDO::ERRMODE_EXCEPTION, true);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
echo "Error in connection 1.\n";
|
||||||
|
print_r($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
breakConnection($conn, $conn_break);
|
||||||
|
|
||||||
|
$query = "SELECT * FROM $tableName";
|
||||||
|
try {
|
||||||
|
$stmt = $conn->prepare($query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
|
||||||
|
if (!$stmt || !$stmt->execute()) {
|
||||||
|
echo "Statement 1 failed.\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
$row_count = $stmt->rowCount();
|
||||||
|
if ($row_count != 9) {
|
||||||
|
echo "Unexpected $row_count rows in result set.\n";
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
echo "Error executing query with connection 1.\n";
|
||||||
|
print_r($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($stmt);
|
||||||
|
unset($conn);
|
||||||
|
|
||||||
|
// second connection
|
||||||
|
try {
|
||||||
|
$conn = connect($connectionInfo, array(), PDO::ERRMODE_EXCEPTION, true);
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
echo "Error in connection 2.\n";
|
||||||
|
print_r($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
breakConnection($conn, $conn_break);
|
||||||
|
|
||||||
|
// would connection be able to resume here if connection pooling is enabled?
|
||||||
|
try {
|
||||||
|
$stmt2 = $conn->query($query);
|
||||||
|
if (!$stmt2) {
|
||||||
|
echo "Statement 2 failed.\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
$col_count = $stmt2->columnCount();
|
||||||
|
if ($col_count != 2) {
|
||||||
|
echo "Unexpected $col_count columns in result set.\n";
|
||||||
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
|
echo "Error executing query with connection 2.\n";
|
||||||
|
print_r($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
dropTable($conn, $tableName);
|
||||||
|
|
||||||
|
echo "Done\n";
|
||||||
|
|
||||||
|
unset($stmt2);
|
||||||
|
unset($conn);
|
||||||
|
unset($conn_break);
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
Done
|
112
test/functional/sqlsrv/srv_678_conn_resiliency_pooling.phpt
Normal file
112
test/functional/sqlsrv/srv_678_conn_resiliency_pooling.phpt
Normal file
|
@ -0,0 +1,112 @@
|
||||||
|
--TEST--
|
||||||
|
GitHub issue #678 - Idle Connection Resiliency doesn't work with Connection Pooling
|
||||||
|
--DESCRIPTION--
|
||||||
|
Verifies that the issue has been fixed with ODBC 17.1
|
||||||
|
--ENV--
|
||||||
|
PHPT_EXEC=true
|
||||||
|
--SKIPIF--
|
||||||
|
<?php require('skipif_protocol_not_tcp.inc');
|
||||||
|
require('skipif_version_less_than_2k14.inc'); ?>
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
require_once("MsCommon.inc");
|
||||||
|
|
||||||
|
function checkODBCVersion($conn)
|
||||||
|
{
|
||||||
|
$msodbcsql_ver = sqlsrv_client_info($conn)['DriverVer'];
|
||||||
|
$vers = explode(".", $msodbcsql_ver);
|
||||||
|
|
||||||
|
if ($vers[0] >= 17 && $vers[1] > 0){
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function breakConnection($conn, $conn_break)
|
||||||
|
{
|
||||||
|
$stmt1 = sqlsrv_query($conn, "SELECT @@SPID");
|
||||||
|
if (sqlsrv_fetch($stmt1)) {
|
||||||
|
$spid=sqlsrv_get_field($stmt1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
$stmt2 = sqlsrv_prepare($conn_break, "KILL ".$spid);
|
||||||
|
sqlsrv_execute($stmt2);
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// create a connection for create the table and breaking other connections
|
||||||
|
$conn_break = sqlsrv_connect($server, array("Database"=>$database, "UID"=>$uid, "PWD"=>$pwd));
|
||||||
|
|
||||||
|
if (! checkODBCVersion($conn_break)) {
|
||||||
|
echo "Done\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$tableName = "test_connres";
|
||||||
|
|
||||||
|
dropTable($conn_break, $tableName);
|
||||||
|
|
||||||
|
$sql = "CREATE TABLE $tableName (c1 INT, c2 VARCHAR(40))";
|
||||||
|
$stmt = sqlsrv_query($conn_break, $sql);
|
||||||
|
|
||||||
|
$sql = "INSERT INTO $tableName VALUES (?, ?)";
|
||||||
|
for ($t = 200; $t < 209; $t++) {
|
||||||
|
$ts = substr(sha1($t), 0, 5);
|
||||||
|
$params = array($t, $ts);
|
||||||
|
$stmt = sqlsrv_prepare($conn_break, $sql, $params);
|
||||||
|
sqlsrv_execute($stmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// first connection
|
||||||
|
$connectionInfo = array("Database"=>$database, "UID"=>$uid, "PWD"=>$pwd,
|
||||||
|
"ConnectionPooling"=>true, "ConnectRetryCount"=>10,
|
||||||
|
"ConnectRetryInterval"=>10 );
|
||||||
|
|
||||||
|
$conn = sqlsrv_connect($server, $connectionInfo);
|
||||||
|
|
||||||
|
breakConnection($conn, $conn_break);
|
||||||
|
|
||||||
|
$query = "SELECT * FROM $tableName";
|
||||||
|
$stmt = sqlsrv_query($conn, $query, array(), array("Scrollable"=>"buffered"));
|
||||||
|
if ($stmt === false) {
|
||||||
|
echo "Error in connection 1.\n";
|
||||||
|
print_r(sqlsrv_errors());
|
||||||
|
} else {
|
||||||
|
$row_count = sqlsrv_num_rows($stmt);
|
||||||
|
if ($row_count != 9) {
|
||||||
|
echo "Unexpected $row_count rows in result set.\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlsrv_free_stmt($stmt);
|
||||||
|
sqlsrv_close($conn);
|
||||||
|
|
||||||
|
// second connection
|
||||||
|
$conn = sqlsrv_connect($server, $connectionInfo);
|
||||||
|
|
||||||
|
breakConnection($conn, $conn_break);
|
||||||
|
|
||||||
|
// would connection be able to resume here if connection pooling is enabled?
|
||||||
|
$stmt2 = sqlsrv_query($conn, $query);
|
||||||
|
if ($stmt2 === false) {
|
||||||
|
echo "Error in connection 2.\n";
|
||||||
|
print_r(sqlsrv_errors());
|
||||||
|
} else {
|
||||||
|
$num_fields = sqlsrv_num_fields($stmt2);
|
||||||
|
if ($num_fields != 2) {
|
||||||
|
echo "Unexpected $num_fields columns in result set.\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dropTable($conn, $tableName);
|
||||||
|
|
||||||
|
echo "Done\n";
|
||||||
|
|
||||||
|
sqlsrv_free_stmt($stmt2);
|
||||||
|
sqlsrv_close($conn);
|
||||||
|
sqlsrv_close($conn_break);
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
Done
|
Loading…
Reference in a new issue