Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1b2d648

Browse files
Add test for single connection across multiple threads.
1 parent 0997f34 commit 1b2d648

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

‎SQLiteTests/ConnectionTests.swift‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,5 +313,26 @@ class ConnectionTests : SQLiteTestCase {
313313
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(10 * NSEC_PER_MSEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), db.interrupt)
314314
AssertThrows(try stmt.run())
315315
}
316+
317+
func test_concurrent_access_single_connection() {
318+
let conn = try! Connection("\(NSTemporaryDirectory())/SQLite.swift Connection Tests.sqlite")
319+
try! conn.execute("DROP TABLE IF EXISTS test; CREATE TABLE test(value);")
320+
try! conn.run("INSERT INTO test(value) VALUES(?)", 0)
321+
322+
let q = dispatch_queue_create("Readers", DISPATCH_QUEUE_CONCURRENT);
323+
var finished = false
324+
325+
for _ in 0..<100 {
326+
dispatch_async(q) {
327+
while !finished {
328+
_ = try! conn.prepare("SELECT value FROM test")
329+
}
330+
}
331+
}
332+
333+
// Give the threads some time to conflict
334+
sleep(5)
335+
finished = true
336+
}
316337

317338
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /