System.Data.SQLite
Check-in [b3d05f0aa0]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Enhance/add tests to check memory usage related to ticket [3b9dcdc32d].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tkt-3b9dcdc32d
Files: files | file ages | folders
SHA1: b3d05f0aa025c232b176be3a677b6c70b4c9166c
User & Date: mistachkin 2011-11-28 04:01:26
Context
2011-11-28
04:02
Remove superfluous logging from test. Closed-Leaf check-in: 0ac2dc31fe user: mistachkin tags: tkt-3b9dcdc32d
04:01
Enhance/add tests to check memory usage related to ticket [3b9dcdc32d]. check-in: b3d05f0aa0 user: mistachkin tags: tkt-3b9dcdc32d
2011-11-27
12:26
First attempt to reproduce the issue described in ticket [3b9dcdc32d]. check-in: 85b23122e0 user: mistachkin tags: tkt-3b9dcdc32d
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to Tests/tkt-3b9dcdc32d.eagle.

    16     16   ###############################################################################
    17     17   
    18     18   package require System.Data.SQLite.Test
    19     19   runSQLiteTestPrologue
    20     20   
    21     21   ###############################################################################
    22     22   
    23         -runTest {test tkt-3b9dcdc32d-1.1 {range of REAL type} -setup {
           23  +runTest {test tkt-3b9dcdc32d-1.1 {ZEROBLOB memory leak} -setup {
           24  +  set memory_used(before) [reportSQLiteResources stdout]
    24     25     setupDb [set fileName tkt-3b9dcdc32d-1.1.db]
    25     26   } -body {
    26     27     sql execute $db "CREATE TABLE t1(x INTEGER, y BLOB NULL, z BLOB NULL);"
    27         -  sql execute $db "INSERT INTO t1 (x) VALUES(1);"
    28         -  sql execute $db \
    29         -      "UPDATE t1 SET y = ZEROBLOB(10 * 1024 * 1024) WHERE rowid = 1;"
           28  +
           29  +  for {set i 1} {$i < 10} {incr i} {
           30  +    sql execute $db "INSERT INTO t1 (x) VALUES(?);" \
           31  +        [list param1 String $i]
           32  +
           33  +    sql execute $db \
           34  +        "UPDATE t1 SET y = ZEROBLOB(10 * 1024 * 1024) WHERE rowid = ?;" \
           35  +        [list param1 String $i]
           36  +
           37  +    sql execute $db "UPDATE t1 SET z = ZEROBLOB(10) WHERE rowid = ?;" \
           38  +        [list param1 String $i]
           39  +  }
           40  +
           41  +  set result [sql execute -execute reader -format list $db \
           42  +      "SELECT x, LENGTH(y), LENGTH(z) FROM t1 ORDER BY x;"]
           43  +
           44  +  cleanupDb $fileName; unset -nocomplain db fileName
           45  +  set memory_used(after) [reportSQLiteResources stdout]
           46  +
           47  +  list [expr {$memory_used(after) - $memory_used(before)}] $result
           48  +} -cleanup {
           49  +  if {[info exists fileName]} then {
           50  +    cleanupDb $fileName
           51  +  }
           52  +
           53  +  unset -nocomplain memory_used db fileName
           54  +} -constraints \
           55  +{eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -result \
           56  +{0 {1 10485760 10 2 10485760 10 3 10485760 10 4 10485760 10 5 10485760 10 6\
           57  +10485760 10 7 10485760 10 8 10485760 10 9 10485760 10}}}
           58  +
           59  +###############################################################################
           60  +
           61  +set memory_used(before) [reportSQLiteResources stdout]
           62  +
           63  +###############################################################################
           64  +
           65  +runTest {test tkt-3b9dcdc32d-1.2 {ZEROBLOB leak} -setup {
           66  +  set fileName tkt-3b9dcdc32d-1.2.db
           67  +} -body {
           68  +  set id [object invoke Interpreter.GetActive NextId]
           69  +  set dataSource [file join [getTemporaryPath] $fileName]
           70  +  set name [file rootname [file tail $fileName]]
           71  +
           72  +  set sql(1) { \
           73  +    CREATE TABLE t1(x INTEGER, y BLOB NULL, z BLOB NULL); \
           74  +  }
           75  +
           76  +  set sql(2) { \
           77  +    INSERT INTO t1 (x) VALUES(10); \
           78  +  }
           79  +
           80  +  set sql(3) { \
           81  +    UPDATE t1 SET y = ZEROBLOB(10 * 1024 * 1024) WHERE rowid = 1; \
           82  +  }
           83  +
           84  +  set sql(4) { \
           85  +    UPDATE t1 SET z = ZEROBLOB(10) WHERE rowid = 1; \
           86  +  }
           87  +
           88  +  unset -nocomplain results errors
           89  +
           90  +  set code [compileCSharpWith [subst {
           91  +    using System;
           92  +    using System.Data.SQLite;
           93  +    using System.Diagnostics;
           94  +    using System.IO;
           95  +
           96  +    namespace _Dynamic${id}
           97  +    {
           98  +      public class Test${id}
           99  +      {
          100  +        public static void Main()
          101  +        {
          102  +          using (SQLiteConnection connection = new SQLiteConnection(
          103  +              "Data Source=${dataSource};"))
          104  +          {
          105  +            connection.Open();
          106  +            connection.LogMessage(0, "Connection opened.");
          107  +
          108  +            SQLiteCommand command1 = new SQLiteCommand("${sql(1)}",
          109  +                connection);
          110  +
          111  +            command1.ExecuteNonQuery();
          112  +
          113  +            SQLiteCommand command2 = new SQLiteCommand("${sql(2)}",
          114  +                connection);
          115  +
          116  +            command2.ExecuteNonQuery();
          117  +
          118  +            SQLiteCommand command3 = new SQLiteCommand("${sql(3)}",
          119  +                connection);
          120  +
          121  +            command3.ExecuteNonQuery();
          122  +
          123  +            SQLiteCommand command4 = new SQLiteCommand("${sql(4)}",
          124  +                connection);
          125  +
          126  +            command4.ExecuteNonQuery();
          127  +          }
    30    128   
    31         -  sql execute $db "UPDATE t1 SET z = ZEROBLOB(10) WHERE rowid = 1;"
          129  +          GC.Collect();
          130  +          GC.WaitForPendingFinalizers();
          131  +          GC.Collect();
          132  +        }
          133  +      }
          134  +    }
          135  +  }] results errors System.Data.SQLite.dll]
    32    136   
    33         -  sql execute -execute reader -format list $db \
    34         -      "SELECT x, LENGTH(y), LENGTH(z) FROM t1 ORDER BY x;"
          137  +  list $code $results \
          138  +      [expr {[info exists errors] ? $errors : ""}] \
          139  +      [expr {$code eq "Ok" ? [catch {
          140  +        object invoke _Dynamic${id}.Test${id} Main
          141  +      } result] : [set result ""]}] $result \
          142  +      [set memory_used(after) [reportSQLiteResources stdout]]
    35    143   } -cleanup {
    36    144     cleanupDb $fileName
    37    145   
    38         -  unset -nocomplain db fileName
          146  +  unset -nocomplain result code results errors sql dataSource id db fileName
    39    147   } -constraints \
    40         -{eagle monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} -result \
    41         -{1 10485760 10}}
          148  +{eagle logFile monoBug28 command.sql compile.DATA SQLite System.Data.SQLite} \
          149  +-match regexp -result [appendArgs "^Ok\
          150  +System#CodeDom#Compiler#CompilerResults#\\d+ \\{\\} 0 \\{\\} "\
          151  +$memory_used(before) \$]}
          152  +
          153  +###############################################################################
          154  +
          155  +unset -nocomplain memory_used
    42    156   
    43    157   ###############################################################################
    44    158   
    45    159   runSQLiteTestEpilogue
    46    160   runTestEpilogue