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 605ac12

Browse files
committed
Merge branch 'test' of https://github.com/nickmshelley/SQLite.swift into nickmshelley-test
2 parents ae406af + 72ee02c commit 605ac12

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

‎Tests/SQLiteTests/ConnectionTests.swift‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,30 @@ class ConnectionTests : SQLiteTestCase {
382382
_ = DispatchQueue(label: "queue", qos: .background).asyncAfter(deadline: deadline, execute: db.interrupt)
383383
AssertThrows(try stmt.run())
384384
}
385+
386+
func test_concurrent_access_single_connection() {
387+
let conn = try! Connection("\(NSTemporaryDirectory())/SQLite.swift Connection Tests.sqlite")
388+
try! conn.execute("DROP TABLE IF EXISTS test; CREATE TABLE test(value);")
389+
try! conn.run("INSERT INTO test(value) VALUES(?)", 0)
390+
391+
let q = dispatch_queue_create("Readers", DISPATCH_QUEUE_CONCURRENT);
392+
393+
var reads = [0, 0, 0, 0, 0]
394+
var finished = false
395+
for index in 0..<5 {
396+
dispatch_async(q) {
397+
while !finished {
398+
_ = try! conn.prepare("SELECT value FROM test")
399+
reads[index] += 1
400+
}
401+
}
402+
}
403+
404+
while !finished {
405+
sleep(1)
406+
finished = reads.reduce(true) { 0ドル && (1ドル > 500) }
407+
}
408+
}
385409

386410
}
387411

0 commit comments

Comments
(0)

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