Conn res fix (#1091)

This commit is contained in:
David Puglielli 2020-02-06 07:42:20 -08:00 committed by GitHub
parent e90fd2c4a4
commit 5455b4dcb8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 50 deletions

View file

@ -52,8 +52,12 @@ function generateTables($server, $uid, $pwd, $dbName, $tableName1, $tableName2)
// Break connection by getting the session ID and killing it. // Break connection by getting the session ID and killing it.
// Note that breaking a connection and testing reconnection requires a // Note that breaking a connection and testing reconnection requires a
// TCP/IP protocol connection (as opposed to a Shared Memory protocol). // TCP/IP protocol connection (as opposed to a Shared Memory protocol).
// Wait one second before and after breaking to ensure the break occurs
// in the correct order, otherwise there may be timing issues in Linux
// that can cause tests to fail intermittently and unpredictably.
function breakConnection($conn, $conn_break) function breakConnection($conn, $conn_break)
{ {
sleep(1);
$stmt1 = $conn->query("SELECT @@SPID"); $stmt1 = $conn->query("SELECT @@SPID");
$obj = $stmt1->fetch(PDO::FETCH_NUM); $obj = $stmt1->fetch(PDO::FETCH_NUM);
$spid = $obj[0]; $spid = $obj[0];

View file

@ -17,8 +17,7 @@ function GenerateTables( $server, $uid, $pwd, $dbName, $tableName1, $tableName2
$connectionInfo = array("Database"=>$dbName, "uid"=>$uid, "pwd"=>$pwd); $connectionInfo = array("Database"=>$dbName, "uid"=>$uid, "pwd"=>$pwd);
$conn = sqlsrv_connect($server, $connectionInfo); $conn = sqlsrv_connect($server, $connectionInfo);
if ( $conn === false ) if ($conn === false) {
{
die (print_r(sqlsrv_errors())); die (print_r(sqlsrv_errors()));
} }
@ -28,8 +27,7 @@ function GenerateTables( $server, $uid, $pwd, $dbName, $tableName1, $tableName2
// Insert data // Insert data
$sql = "INSERT INTO $tableName1 VALUES (?, ?)"; $sql = "INSERT INTO $tableName1 VALUES (?, ?)";
for( $t = 100; $t < 116; $t++ ) for ($t = 100; $t < 116; $t++) {
{
$ts = substr(sha1($t), 0, 5); $ts = substr(sha1($t), 0, 5);
$params = array($t, $ts); $params = array($t, $ts);
$stmt = sqlsrv_prepare($conn, $sql, $params); $stmt = sqlsrv_prepare($conn, $sql, $params);
@ -42,8 +40,7 @@ function GenerateTables( $server, $uid, $pwd, $dbName, $tableName1, $tableName2
// Insert data // Insert data
$sql = "INSERT INTO $tableName2 VALUES (?, ?)"; $sql = "INSERT INTO $tableName2 VALUES (?, ?)";
for( $t = 200; $t < 209; $t++ ) for ($t = 200; $t < 209; $t++) {
{
$ts = substr(sha1($t), 0, 5); $ts = substr(sha1($t), 0, 5);
$params = array($t, $ts); $params = array($t, $ts);
$stmt = sqlsrv_prepare($conn, $sql, $params); $stmt = sqlsrv_prepare($conn, $sql, $params);
@ -56,11 +53,14 @@ function GenerateTables( $server, $uid, $pwd, $dbName, $tableName1, $tableName2
// Break connection by getting the session ID and killing it. // Break connection by getting the session ID and killing it.
// Note that breaking a connection and testing reconnection requires a // Note that breaking a connection and testing reconnection requires a
// TCP/IP protocol connection (as opposed to a Shared Memory protocol). // TCP/IP protocol connection (as opposed to a Shared Memory protocol).
// Wait one second before and after breaking to ensure the break occurs
// in the correct order, otherwise there may be timing issues in Linux
// that can cause tests to fail intermittently and unpredictably.
function BreakConnection($conn, $conn_break) function BreakConnection($conn, $conn_break)
{ {
sleep(1);
$stmt1 = sqlsrv_query($conn, "SELECT @@SPID"); $stmt1 = sqlsrv_query($conn, "SELECT @@SPID");
if ( sqlsrv_fetch( $stmt1 ) ) if (sqlsrv_fetch($stmt1)) {
{
$spid=sqlsrv_get_field($stmt1, 0); $spid=sqlsrv_get_field($stmt1, 0);
} }