From bacd91129bf358a9c6a84e37a756e2d40d818f17 Mon Sep 17 00:00:00 2001
From: Jenny Tam <v-yitam@microsoft.com>
Date: Thu, 15 Aug 2019 09:44:53 -0700
Subject: [PATCH 1/4] Used constants in memory stress tests for easier
 configuration

---
 test/functional/output.py                         | 4 +++-
 test/functional/pdo_sqlsrv/PDO81_MemoryCheck.phpt | 4 +++-
 test/functional/sqlsrv/TC81_MemoryCheck.phpt      | 4 +++-
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/test/functional/output.py b/test/functional/output.py
index 4d19409ec..99543bc37 100644
--- a/test/functional/output.py
+++ b/test/functional/output.py
@@ -76,11 +76,13 @@ def gen_XML(logfile, number, logfilename):
     # Generating the xml report.
     if logfilename is True:
         file = open(filename + '.xml', 'w')
+        report = filename
     else:
         file = open('nativeresult' + str(number) + '.xml', 'w')
+        report = 'Native Tests'
     
     file.write('<?xml version="1.0" encoding="UTF-8" ?>' + os.linesep)
-    file.write('<testsuite tests="' + str(num - 1) + '" failures="' + str(failnum) + '" name="Native Tests" >' + os.linesep)
+    file.write('<testsuite tests="' + str(num - 1) + '" failures="' + str(failnum) + '" name="' + report + '" >' + os.linesep)
 
     index = 1
     for test in tests_list:
diff --git a/test/functional/pdo_sqlsrv/PDO81_MemoryCheck.phpt b/test/functional/pdo_sqlsrv/PDO81_MemoryCheck.phpt
index 5513290b6..1dd1c9206 100644
--- a/test/functional/pdo_sqlsrv/PDO81_MemoryCheck.phpt
+++ b/test/functional/pdo_sqlsrv/PDO81_MemoryCheck.phpt
@@ -11,6 +11,8 @@ PHPT_EXEC=true
 <?php
 include 'MsCommon.inc';
 
+const _NUM_PASSES = 20;
+
 function MemCheck($noPasses, $noRows1, $noRows2, $startStep, $endStep, $leakThreshold)
 {
     include 'MsSetup.inc';
@@ -228,7 +230,7 @@ function Repro()
 {
     try
     {
-        MemCheck(20, 10, 15, 1, 3, 0);
+        MemCheck(_NUM_PASSES, 10, 15, 1, 3, 0);
     }
     catch (Exception $e)
     {
diff --git a/test/functional/sqlsrv/TC81_MemoryCheck.phpt b/test/functional/sqlsrv/TC81_MemoryCheck.phpt
index 5845da21f..2dc48d18d 100644
--- a/test/functional/sqlsrv/TC81_MemoryCheck.phpt
+++ b/test/functional/sqlsrv/TC81_MemoryCheck.phpt
@@ -12,6 +12,8 @@ PHPT_EXEC=true
 <?php
 require_once('MsCommon.inc');
 
+const _NUM_PASSES = 20;
+
 function memCheck($noPasses, $noRows1, $noRows2, $startStep, $endStep)
 {
     $testName = "Memory Leakage Check";
@@ -337,7 +339,7 @@ function runTest($noPasses, $noRows, $tableName, $conn, $prepared, $release, $mo
 }
 
 try {
-    memCheck(20, 10, 15, 1, 7);
+    memCheck(_NUM_PASSES, 10, 15, 1, 7);
 } catch (Exception $e) {
     echo $e->getMessage();
 }

From d5dd5f21ad256b9b2ae8d3ca8dbcef9338170ebc Mon Sep 17 00:00:00 2001
From: Jenny Tam <v-yitam@microsoft.com>
Date: Thu, 15 Aug 2019 12:34:33 -0700
Subject: [PATCH 2/4] Added more test cases to pdo stress test

---
 .../pdo_sqlsrv/PDO81_MemoryCheck.phpt         | 56 ++++++++++++++++++-
 test/functional/sqlsrv/TC81_MemoryCheck.phpt  |  6 +-
 2 files changed, 59 insertions(+), 3 deletions(-)

diff --git a/test/functional/pdo_sqlsrv/PDO81_MemoryCheck.phpt b/test/functional/pdo_sqlsrv/PDO81_MemoryCheck.phpt
index 1dd1c9206..50ee4f91b 100644
--- a/test/functional/pdo_sqlsrv/PDO81_MemoryCheck.phpt
+++ b/test/functional/pdo_sqlsrv/PDO81_MemoryCheck.phpt
@@ -12,6 +12,8 @@ PHPT_EXEC=true
 include 'MsCommon.inc';
 
 const _NUM_PASSES = 20;
+const _NUM_ROWS1 = 10;
+const _NUM_ROWS2 = 15;
 
 function MemCheck($noPasses, $noRows1, $noRows2, $startStep, $endStep, $leakThreshold)
 {
@@ -137,6 +139,18 @@ function ExecTest($noPasses, $noRows, $startStep, $endStep, $tableName, $conn, $
                 Trace("$i. Fetch\t - ");
                 break;
 
+            case 4:    // fetchAll
+                Trace("$i. FetchAll\t - ");
+                break;
+                
+            case 5:    // fetch object
+                trace("$i. Fetch Object\t - ");
+                break;
+                
+            case 6:    // fetch column
+                trace("$i. Fetch Column\t - ");
+                break;
+
             default:
                 break;
         }
@@ -200,6 +214,46 @@ function RunTest($noPasses, $noRows, $tableName, $conn, $prepared, $mode)
                 }
                 break;
 
+            case 4:     // fetchAll
+                $stmt = ExecuteQueryEx($conn, $tsql, ($prepared ? false : true));
+                $fldCount = $stmt->columnCount();
+                $result = $stmt->fetchAll();
+                $rowCount = count($result);
+                unset($result);
+                $stmt->closeCursor();
+                unset($stmt);
+                if ($rowCount != $noRows) {
+                    die("$rowCount rows retrieved instead of $noRows\n");
+                }
+                break;
+                
+            case 5:     // fetchObject
+                $stmt = ExecuteQueryEx($conn, $tsql, ($prepared ? false : true));
+                $fldCount = $stmt->columnCount();
+                while ($obj = $stmt->fetchObject()) {
+                    unset($obj);
+                    $rowCount++;
+                }
+                $stmt->closeCursor();
+                unset($stmt);
+                if ($rowCount != $noRows) {
+                    die("$rowCount rows retrieved instead of $noRows\n");
+                }
+                break;
+                
+            case 6:     // fetchColumn
+                $stmt = ExecuteQueryEx($conn, $tsql, ($prepared ? false : true));
+                $fldCount = $stmt->columnCount();
+                $result = $stmt->fetchAll();
+                $rowCount = count($result);
+                unset($result);
+                $stmt->closeCursor();
+                unset($stmt);
+                if ($rowCount != $noRows) {
+                    die("$rowCount rows retrieved instead of $noRows\n");
+                }
+                break;
+                
             default:
                 break;
 
@@ -230,7 +284,7 @@ function Repro()
 {
     try
     {
-        MemCheck(_NUM_PASSES, 10, 15, 1, 3, 0);
+        MemCheck(_NUM_PASSES, _NUM_ROWS1, _NUM_ROWS2, 1, 6, 0);
     }
     catch (Exception $e)
     {
diff --git a/test/functional/sqlsrv/TC81_MemoryCheck.phpt b/test/functional/sqlsrv/TC81_MemoryCheck.phpt
index 2dc48d18d..40f84a6a2 100644
--- a/test/functional/sqlsrv/TC81_MemoryCheck.phpt
+++ b/test/functional/sqlsrv/TC81_MemoryCheck.phpt
@@ -7,12 +7,14 @@ emalloc (which only allocate memory in the memory space allocated for the PHP pr
 PHPT_EXEC=true
 --SKIPIF--
 <?php require('skipif_versions_old.inc'); ?>
-<?php require('skipif_azure.inc'); ?>
+<?php require('skipif_azure_dw.inc'); ?>
 --FILE--
 <?php
 require_once('MsCommon.inc');
 
 const _NUM_PASSES = 20;
+const _NUM_ROWS1 = 10;
+const _NUM_ROWS2 = 15;
 
 function memCheck($noPasses, $noRows1, $noRows2, $startStep, $endStep)
 {
@@ -339,7 +341,7 @@ function runTest($noPasses, $noRows, $tableName, $conn, $prepared, $release, $mo
 }
 
 try {
-    memCheck(_NUM_PASSES, 10, 15, 1, 7);
+    memCheck(_NUM_PASSES, _NUM_ROWS1, _NUM_ROWS2, 1, 7);
 } catch (Exception $e) {
     echo $e->getMessage();
 }

From 3d8c68e16da641c0e75b5077938cf8a6dbb9085f Mon Sep 17 00:00:00 2001
From: Jenny Tam <v-yitam@microsoft.com>
Date: Mon, 19 Aug 2019 16:34:39 -0700
Subject: [PATCH 3/4] Fixed a typo as per review

---
 test/functional/pdo_sqlsrv/PDO81_MemoryCheck.phpt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/test/functional/pdo_sqlsrv/PDO81_MemoryCheck.phpt b/test/functional/pdo_sqlsrv/PDO81_MemoryCheck.phpt
index 50ee4f91b..42919b193 100644
--- a/test/functional/pdo_sqlsrv/PDO81_MemoryCheck.phpt
+++ b/test/functional/pdo_sqlsrv/PDO81_MemoryCheck.phpt
@@ -244,7 +244,7 @@ function RunTest($noPasses, $noRows, $tableName, $conn, $prepared, $mode)
             case 6:     // fetchColumn
                 $stmt = ExecuteQueryEx($conn, $tsql, ($prepared ? false : true));
                 $fldCount = $stmt->columnCount();
-                $result = $stmt->fetchAll();
+                $result = $stmt->fetchColumn();
                 $rowCount = count($result);
                 unset($result);
                 $stmt->closeCursor();

From ac5021245d83bfd6621570d30f04db4d1acce0a2 Mon Sep 17 00:00:00 2001
From: Jenny Tam <v-yitam@microsoft.com>
Date: Mon, 19 Aug 2019 16:56:35 -0700
Subject: [PATCH 4/4] Used while loop for fetchColumn

---
 test/functional/pdo_sqlsrv/PDO81_MemoryCheck.phpt | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/test/functional/pdo_sqlsrv/PDO81_MemoryCheck.phpt b/test/functional/pdo_sqlsrv/PDO81_MemoryCheck.phpt
index 42919b193..1153d6ac4 100644
--- a/test/functional/pdo_sqlsrv/PDO81_MemoryCheck.phpt
+++ b/test/functional/pdo_sqlsrv/PDO81_MemoryCheck.phpt
@@ -244,9 +244,11 @@ function RunTest($noPasses, $noRows, $tableName, $conn, $prepared, $mode)
             case 6:     // fetchColumn
                 $stmt = ExecuteQueryEx($conn, $tsql, ($prepared ? false : true));
                 $fldCount = $stmt->columnCount();
-                $result = $stmt->fetchColumn();
-                $rowCount = count($result);
-                unset($result);
+                // Check for "false" to terminate because fetchColumn may return NULL
+                while (($result = $stmt->fetchColumn()) !== false) {
+                    unset($result);
+                    $rowCount++;
+                }
                 $stmt->closeCursor();
                 unset($stmt);
                 if ($rowCount != $noRows) {