Skip to content

Modified test_largeData for Linux CI #954

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 91 additions & 52 deletions test/functional/sqlsrv/test_largeData.phpt
Original file line number Diff line number Diff line change
@@ -1,119 +1,158 @@
--TEST--
send a large amount (10MB) using encryption.
Send a large amount (10MB) using encryption. In a Linux CI environment use a smaller size.
--SKIPIF--
<?php require('skipif_azure_dw.inc'); ?>
--FILE--
<?php
class my_stream {

var $total_read = 0;
class my_stream
{
public $total_read = 0;

function stream_open ($path, $mode, $options, &$opened_path )
public function stream_open($path, $mode, $options, &$opened_path)
{
$this->total_read = 0;
return true;
}

function stream_read( $count )
public function stream_read($count)
{
if( $this->total_read > 20000000 ) {
global $limit;
if ($this->total_read > $limit) {
return 0;
}
global $packets;
++$packets;
$str = str_repeat( "A", $count );

// 8192 is passed to stream_read as $count
$str = str_repeat("A", $count);
$this->total_read += $count;
return $str;
}

function stream_write($data)
public function stream_write($data)
{
}

function stream_tell()
public function stream_tell()
{
return $this->total_read;
}

function stream_eof()
public function stream_eof()
{
return $this->total_read > 20000000;
global $limit;
return $this->total_read > $limit;
}

function stream_seek($offset, $whence)
public function stream_seek($offset, $whence)
{
// For the purpose of this test only support SEEK_SET to $offset 0
if ($whence == SEEK_SET && $offset == 0) {
$this->total_read = $offset;
return true;
}
}
return false;
}
}

function isServerInLinux($conn)
{
// This checks if SQL Server is running in Linux (Docker) in a CI environment
// If so, the major version must be 14 or above (SQL Server 2017 or above)
$serverVer = sqlsrv_server_info($conn)['SQLServerVersion'];
if (explode('.', $serverVer)[0] < 14) {
return false;
}

// The view sys.dm_os_host_info, available starting in SQL Server 2017, is somewhat similar to sys.dm_os_windows_info.
// It returns one row that displays operating system version information and has columns to differentiate
// Windows and Linux.
$stmt = sqlsrv_query($conn, 'SELECT host_platform FROM sys.dm_os_host_info');
if ($stmt && sqlsrv_fetch($stmt)) {
$host = sqlsrv_get_field($stmt, 0);
return ($host === 'Linux');
}

return false;
}

set_time_limit(0);
sqlsrv_configure( 'WarningsReturnAsErrors', 0 );
sqlsrv_configure( 'LogSubsystems', SQLSRV_LOG_SYSTEM_ALL );
sqlsrv_configure('WarningsReturnAsErrors', 0);
sqlsrv_configure('LogSubsystems', SQLSRV_LOG_SYSTEM_ALL);

$packets = 0;
$limit = 20000000;

$result = stream_wrapper_register( "mystr", "my_stream" );
if( !$result ) {
die( "Couldn't register stream class." );
$result = stream_wrapper_register("mystr", "my_stream");
if (!$result) {
die("Couldn't register stream class.");
}

require( 'MsCommon.inc' );
require_once('MsCommon.inc');

$conn = Connect(array( 'Encrypt' => true, 'TrustServerCertificate' => true ));
if( $conn === false ) {
die( print_r( sqlsrv_errors(), true ));
if ($conn === false) {
die(print_r(sqlsrv_errors(), true));
}

$stmt = sqlsrv_query( $conn, "IF OBJECT_ID('test_lob', 'U') IS NOT NULL DROP TABLE test_lob" );
if( $stmt !== false ) sqlsrv_free_stmt( $stmt );
// In a Linux CI environment use a smaller size
if (isServerInLinux($conn)) {
$limit /= 100;
}

$stmt = sqlsrv_query($conn, "IF OBJECT_ID('test_lob', 'U') IS NOT NULL DROP TABLE test_lob");
if ($stmt !== false) {
sqlsrv_free_stmt($stmt);
}

$stmt = sqlsrv_query( $conn, "CREATE TABLE test_lob (id tinyint, stuff varbinary(max))" );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
$stmt = sqlsrv_query($conn, "CREATE TABLE test_lob (id tinyint, stuff varbinary(max))");
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
sqlsrv_free_stmt( $stmt );
sqlsrv_free_stmt($stmt);

$lob = fopen( "mystr://test_data", "rb" );
if( !$lob ) {
die( "failed opening test stream.\n" );
$lob = fopen("mystr://test_data", "rb");
if (!$lob) {
die("failed opening test stream.\n");
}
$stmt = sqlsrv_query( $conn, "INSERT INTO test_lob (id, stuff) VALUES (?,?)", array( 1, array( $lob, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY('max'))));
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
$stmt = sqlsrv_query($conn, "INSERT INTO test_lob (id, stuff) VALUES (?,?)", array( 1, array( $lob, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY), SQLSRV_SQLTYPE_VARBINARY('max'))));
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}

while( $result = sqlsrv_send_stream_data( $stmt )) {
while ($result = sqlsrv_send_stream_data($stmt)) {
++$packets;
}
if( $result === false ) {
die( print_r( sqlsrv_errors(), true ));
if ($result === false) {
die(print_r(sqlsrv_errors(), true));
}
echo "$packets sent.\n";

$stmt = sqlsrv_query( $conn, "SELECT LEN(stuff) FROM test_lob" );
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true ));
// Number of packets sent should be $limit / 8192 (rounded up)
// Length of the varbinary = $packetsSent * 8192 + 1 (HEX 30 appended at the end)
$packetsSent = ceil($limit / 8192);
$length = $packetsSent * 8192 + 1;
if ($packets != $packetsSent) {
echo "$packets sent.\n";
}
while( $result = sqlsrv_fetch_array( $stmt )) {
print_r( $result );

$stmt = sqlsrv_query($conn, "SELECT LEN(stuff) FROM test_lob");
if ($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
while ($result = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_NUMERIC)) {
if ($result[0] != $length) {
print_r($result);
}
}

sqlsrv_query( $conn, "DROP TABLE test_lob" );
sqlsrv_query($conn, "DROP TABLE test_lob");

sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);

sleep(10); // since this is a long test, we give the database some time to finish

echo "Done\n";
?>
--EXPECT--
2442 sent.
Array
(
[0] => 20004865
[] => 20004865
)
Done