System.Data.SQLite

Check-in [2cb2ae35a3]
Login

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

Overview
Comment:Refinements to the test for ticket [5cee5409f8], with a special focus on the new WaitForEnlistmentReset method.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | tkt-5cee5409f8
Files: files | file ages | folders
SHA1: 2cb2ae35a37a31b2270dd61b6d3740f1d4dc6a15
User & Date: mistachkin 2018-01-27 22:24:34.635
Context
2018-01-28
05:27
Update version history docs. Closed-Leaf check-in: 81d4c53f90 user: mistachkin tags: tkt-5cee5409f8
2018-01-27
22:24
Refinements to the test for ticket [5cee5409f8], with a special focus on the new WaitForEnlistmentReset method. check-in: 2cb2ae35a3 user: mistachkin tags: tkt-5cee5409f8
21:13
Add initial tests for ticket [5cee5409f8]. check-in: e30a873204 user: mistachkin tags: tkt-5cee5409f8
Changes
Unified Diff Ignore Whitespace Patch
Changes to Tests/tkt-5cee5409f8.eagle.
29
30
31
32
33
34
35

36
37
38
39
40
41

42
43
44
45
46
47
48
  set dataSource [file join [getDatabaseDirectory] $fileName]

  unset -nocomplain results errors

  set code [compileCSharpWith [subst {
    using System;
    using System.Data.SQLite;

    using System.Transactions;

    namespace _Dynamic${id}
    {
      public static class Test${id}
      {

        private sealed class EnlistmentNotification : IEnlistmentNotification
        {
          #region Private Data
          private bool forceRollback;
          #endregion

          /////////////////////////////////////////////////////////////////////







>






>







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  set dataSource [file join [getDatabaseDirectory] $fileName]

  unset -nocomplain results errors

  set code [compileCSharpWith [subst {
    using System;
    using System.Data.SQLite;
    using System.Threading;
    using System.Transactions;

    namespace _Dynamic${id}
    {
      public static class Test${id}
      {
        #region Private EnlistmentNotification Class
        private sealed class EnlistmentNotification : IEnlistmentNotification
        {
          #region Private Data
          private bool forceRollback;
          #endregion

          /////////////////////////////////////////////////////////////////////
94
95
96
97
98
99
100








101
102
103

104
105


106
107
108
109
110
111
112
113
          {
            Transaction.Current.EnlistDurable(
                Guid.NewGuid(), new EnlistmentNotification(forceRollback),
                EnlistmentOptions.None);
          }
          #endregion
        }









        ///////////////////////////////////////////////////////////////////////


        public static void DoTransactions(SQLiteConnection connection)
        {


          for (int iteration = 0; iteration < 1000; iteration++)
          {
            using (TransactionScope transactionScope = new TransactionScope())
            {
              EnlistmentNotification.UseDistributedTransaction(false);

              TransactionInformation transactionInformation =
                  Transaction.Current.TransactionInformation;







>
>
>
>
>
>
>
>



>
|

>
>
|







96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
          {
            Transaction.Current.EnlistDurable(
                Guid.NewGuid(), new EnlistmentNotification(forceRollback),
                EnlistmentOptions.None);
          }
          #endregion
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region Private Static Data
        private static int resetCount;
        private static int timeoutCount;
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region Private Static Methods
        private static void DoTransactions(SQLiteConnection connection)
        {
          Random random = new Random();

          for (int iteration = 0; iteration < 10000; iteration++)
          {
            using (TransactionScope transactionScope = new TransactionScope())
            {
              EnlistmentNotification.UseDistributedTransaction(false);

              TransactionInformation transactionInformation =
                  Transaction.Current.TransactionInformation;
125
126
127
128
129
130
131
132










































133
134
135
136
137
138
139
140
141
142
143
144
145
146

147
148
149
150
151
152
153
154
155


156
157
158
159
160
161
162
163
164
165
166
167
                command.CommandText = "INSERT INTO t1(x) VALUES(?);";
                command.Parameters.Add(new SQLiteParameter("", iteration));
                command.ExecuteNonQuery();
              }

              transactionScope.Complete();
            }
          }










































        }

        ///////////////////////////////////////////////////////////////////////

        public static void Main()
        {
          using (SQLiteConnection connection = new SQLiteConnection(
              "Data Source=${dataSource};[getTestProperties]"))
          {
            connection.Open();

            DoTransactions(connection);
          }
        }

      }
    }
  }] true true true results errors System.Data.SQLite.dll]

  list $code $results \
      [expr {[info exists errors] ? $errors : ""}] \
      [expr {$code eq "Ok" ? [catch {
        object invoke _Dynamic${id}.Test${id} Main
      } result] : [set result ""]}] $result


} -cleanup {
  cleanupDb $fileName

  unset -nocomplain result results errors code dataSource id db fileName
} -constraints {eagle command.object monoBug211 monoBug54 command.sql\
compile.DATA SQLite System.Data.SQLite compileCSharp} -match regexp -result \
{^Ok System#CodeDom#Compiler#CompilerResults#\d+ \{\} 0 \{\}$}}

###############################################################################

runSQLiteTestEpilogue
runTestEpilogue







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






<
<
<
<
|
<
|
<
>







|
|
>
>






|





138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193




194

195

196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
                command.CommandText = "INSERT INTO t1(x) VALUES(?);";
                command.Parameters.Add(new SQLiteParameter("", iteration));
                command.ExecuteNonQuery();
              }

              transactionScope.Complete();
            }

            Thread.Sleep(random.Next(10));
          }
        }

        ///////////////////////////////////////////////////////////////////////

        private static void WaitOnEnlistments(object state)
        {
          SQLiteConnection connection = (SQLiteConnection)state;
          Random random = new Random();

          for (int iteration = 0; iteration < 1000; iteration++)
          {
            if (connection.WaitForEnlistmentReset(1))
              Interlocked.Increment(ref resetCount);
            else
              Interlocked.Increment(ref timeoutCount);

            Thread.Sleep(random.Next(100));
          }
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region Public Static Methods
        public static string DoTest()
        {
          using (SQLiteConnection connection = new SQLiteConnection(
              "Data Source=${dataSource};[getTestProperties]"))
          {
            ThreadPool.QueueUserWorkItem(WaitOnEnlistments, connection);

            connection.Open();

            DoTransactions(connection);
          }

          int count1 = Interlocked.CompareExchange(ref resetCount, 0, 0);
          int count2 = Interlocked.CompareExchange(ref timeoutCount, 0, 0);

          return String.Format("{0}, {1}", count1, count2);
        }

        ///////////////////////////////////////////////////////////////////////

        public static void Main()
        {




          // do nothing.

        }

        #endregion
      }
    }
  }] true true true results errors System.Data.SQLite.dll]

  list $code $results \
      [expr {[info exists errors] ? $errors : ""}] \
      [expr {$code eq "Ok" ? [catch {
        object invoke _Dynamic${id}.Test${id} DoTest
      } result] : [set result ""]}] \
      [expr {[lindex $result 0] > 0}] \
      [expr {[lindex $result 1] > 0}]
} -cleanup {
  cleanupDb $fileName

  unset -nocomplain result results errors code dataSource id db fileName
} -constraints {eagle command.object monoBug211 monoBug54 command.sql\
compile.DATA SQLite System.Data.SQLite compileCSharp} -match regexp -result \
{^Ok System#CodeDom#Compiler#CompilerResults#\d+ \{\} 0 True True$}}

###############################################################################

runSQLiteTestEpilogue
runTestEpilogue