From 7e0bf91eecb9a81f4dc489e07015311d9b6c8d63 Mon Sep 17 00:00:00 2001 From: Jenny Tam Date: Mon, 13 May 2019 15:46:25 -0700 Subject: [PATCH] Fixed two failing tests (#991) --- ...ry_encoding_error_bound_by_name_errors.phpt | 10 ++++++++-- .../sqlsrv/srv_007_login_timeout.phpt | 18 +++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/test/functional/pdo_sqlsrv/pdo_035_binary_encoding_error_bound_by_name_errors.phpt b/test/functional/pdo_sqlsrv/pdo_035_binary_encoding_error_bound_by_name_errors.phpt index 14ccac36..39d30729 100644 --- a/test/functional/pdo_sqlsrv/pdo_035_binary_encoding_error_bound_by_name_errors.phpt +++ b/test/functional/pdo_sqlsrv/pdo_035_binary_encoding_error_bound_by_name_errors.phpt @@ -17,6 +17,7 @@ function bindTypeNoEncoding($conn, $sql, $input) $stmt->setAttribute(constant('PDO::SQLSRV_ATTR_ENCODING'), PDO::SQLSRV_ENCODING_BINARY); $stmt->bindParam(2, $input, PDO::PARAM_LOB); $stmt->execute(); + echo "bindTypeNoEncoding: expected to fail!\n"; } catch (PDOException $e) { $error = '*An encoding was specified for parameter 1. Only PDO::PARAM_LOB and PDO::PARAM_STR can take an encoding option.'; if (!fnmatch($error, $e->getMessage())) { @@ -36,6 +37,7 @@ function bindDefaultEncoding($conn, $sql, $input) $stmt->setAttribute(constant('PDO::SQLSRV_ATTR_ENCODING'), PDO::SQLSRV_ENCODING_BINARY); $stmt->bindParam(2, $input, PDO::PARAM_LOB); $stmt->execute(); + echo "bindDefaultEncoding: expected to fail!\n"; } catch (PDOException $e) { $error = '*Invalid encoding specified for parameter 1.'; if (!fnmatch($error, $e->getMessage())) { @@ -52,8 +54,9 @@ function insertData($conn, $sql, $input) $stmt = $conn->prepare($sql); $stmt->bindParam(1, $value); - $stmt->setAttribute(constant('PDO::SQLSRV_ATTR_ENCODING'), PDO::SQLSRV_ENCODING_BINARY); - $stmt->bindParam(2, $input, PDO::PARAM_LOB); + // Specify binary encoding for the second parameter only such that the first + // parameter is unaffected + $stmt->bindParam(2, $input, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_BINARY); $stmt->execute(); } catch (PDOException $e) { echo "Error unexpected in insertData\n"; @@ -68,6 +71,7 @@ function invalidEncoding1($conn, $sql) $stmt->bindColumn(1, $id, PDO::PARAM_INT, 0, PDO::SQLSRV_ENCODING_UTF8); $stmt->execute(); $stmt->fetch(PDO::FETCH_BOUND); + echo "invalidEncoding1: expected to fail!\n"; } catch (PDOException $e) { $error = '*An encoding was specified for column 1. Only PDO::PARAM_LOB and PDO::PARAM_STR column types can take an encoding option.'; if (!fnmatch($error, $e->getMessage())) { @@ -84,6 +88,7 @@ function invalidEncoding2($conn, $sql) $stmt->bindColumn('Value', $val1, PDO::PARAM_LOB, 0, PDO::SQLSRV_ENCODING_DEFAULT); $stmt->execute(); $stmt->fetch(PDO::FETCH_BOUND); + echo "invalidEncoding2: expected to fail!\n"; } catch (PDOException $e) { $error = '*Invalid encoding specified for column 1.'; if (!fnmatch($error, $e->getMessage())) { @@ -100,6 +105,7 @@ function invalidEncoding3($conn, $sql) $stmt->bindColumn(1, $id, PDO::PARAM_STR, 0, "dummy"); $stmt->execute(); $stmt->fetch(PDO::FETCH_BOUND); + echo "invalidEncoding3: expected to fail!\n"; } catch (PDOException $e) { $error = '*An invalid type or value was given as bound column driver data for column 1. Only encoding constants such as PDO::SQLSRV_ENCODING_UTF8 may be used as bound column driver data.'; if (!fnmatch($error, $e->getMessage())) { diff --git a/test/functional/sqlsrv/srv_007_login_timeout.phpt b/test/functional/sqlsrv/srv_007_login_timeout.phpt index c8fa5cf1..681b149a 100644 --- a/test/functional/sqlsrv/srv_007_login_timeout.phpt +++ b/test/functional/sqlsrv/srv_007_login_timeout.phpt @@ -11,15 +11,23 @@ $serverName = "WRONG_SERVER_NAME"; $t0 = microtime(true); -$conn = sqlsrv_connect($serverName , array("LoginTimeout" => 8)); +// Based on the following reference, a login timeout of less than approximately 10 seconds +// is not reliable. The defaut is 15 seconds so we fix it at 20 seconds. +// https://docs.microsoft.com/sql/connect/odbc/windows/features-of-the-microsoft-odbc-driver-for-sql-server-on-windows + +$timeout = 20; +$conn = sqlsrv_connect($serverName , array("LoginTimeout" => $timeout)); $t1 = microtime(true); -echo "Connection attempt time: " . ($t1 - $t0) . " [sec]\n"; +$elapsed = $t1 - $t0; +$diff = abs($elapsed - $timeout); + +if ($elapsed < $timeout || $diff > 1.0) { + echo "Connection failed at $elapsed secs. Leeway is 1.0 sec but the difference is $diff\n"; +} print "Done"; ?> - ---EXPECTREGEX-- -Connection attempt time: [7-9]\.[0-9]+ \[sec\] +--EXPECT-- Done