Skip to content

Commit b6af096

Browse files
tofutimoysteinkrog
authored andcommitted
set journal_mode and busy_timeout to try to get async stress test to work
1 parent 68a16f0 commit b6af096

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

tests/AsyncTests.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using PCLStorage;
99
using SQLite.Net.Async;
1010
using SQLite.Net.Attributes;
11+
using System.Diagnostics;
1112

1213

1314
namespace SQLite.Net.Tests
@@ -164,8 +165,16 @@ public async Task GetAsync()
164165
[Test]
165166
public async Task StressAsync()
166167
{
168+
const int defaultBusyTimeout = 100;
169+
167170
SQLiteAsyncConnection globalConn = GetAsyncConnection();
168171

172+
var journalMode = await globalConn.ExecuteScalarAsync<string>("PRAGMA journal_mode = wal"); // = wal");
173+
Debug.WriteLine("journal_mode: " + journalMode);
174+
var busyTimeout = await globalConn.ExecuteScalarAsync<string>(
175+
string.Format("PRAGMA busy_timeout = {0}", defaultBusyTimeout));
176+
Debug.WriteLine("busy_timeout: " + busyTimeout);
177+
169178
await globalConn.CreateTableAsync<Customer>();
170179

171180
int n = 500;
@@ -178,6 +187,12 @@ public async Task StressAsync()
178187
try
179188
{
180189
SQLiteAsyncConnection conn = GetAsyncConnection();
190+
191+
// Each connection retains the global journal_mode but somehow resets busy_timeout to 100
192+
busyTimeout = await globalConn.ExecuteScalarAsync<string>(
193+
string.Format("PRAGMA busy_timeout = {0}", defaultBusyTimeout));
194+
// Debug.WriteLine("busy_timeout: " + busyTimeout);
195+
181196
var obj = new Customer
182197
{
183198
FirstName = i.ToString(),
@@ -212,9 +227,17 @@ public async Task StressAsync()
212227
}
213228

214229
await Task.WhenAll(tasks);
215-
int count = await globalConn.Table<Customer>().CountAsync();
230+
231+
int j = 0;
232+
foreach (var error in errors)
233+
{
234+
Debug.WriteLine("{0} {1}", j++, error);
235+
}
216236

217237
Assert.AreEqual(0, errors.Count);
238+
239+
// could be locked
240+
int count = await globalConn.Table<Customer>().CountAsync();
218241
Assert.AreEqual(n, count);
219242
}
220243

@@ -1079,4 +1102,4 @@ public async Task TestGetMappingAsync()
10791102
Assert.AreEqual("AGoodColumnName", mapping.Columns[1].Name);
10801103
}
10811104
}
1082-
}
1105+
}

0 commit comments

Comments
 (0)