DatabaseQueue.inTransaction() and DatabaseQueue.inDatabase() are no longer reentrant, since we don’t (yet?) implement it in a robust way.

This commit is contained in:
Gwendal Roué committed 2015-09-12 13:22:01 +02:00
1 parent 768880ae91
commit 2fee6799d0
2 files changed
+26 -27

No files matched your search

@@ -382,29 +382,31 @@ class DatabaseTests : GRDBTestCase {
}
}
func testInDatabaseIsReentrant() {
var success = false
dbQueue.inDatabase { db in
self.dbQueue.inDatabase { db in
success = true
}
}
XCTAssertTrue(success)
}
func testInTransactionInsideInDatabaseIsReentrant() {
var success = false
assertNoError {
try dbQueue.inDatabase { db in
try self.dbQueue.inTransaction { db in
success = true
return .Commit
}
}
}
XCTAssertTrue(success)
}
// CRASH TEST: this test must crash
// func testInDatabaseIsNotReentrant() {
// var success = false
// dbQueue.inDatabase { db in
// self.dbQueue.inDatabase { db in
// success = true
// }
// }
// XCTAssertTrue(success)
// }
// CRASH TEST: this test must crash
// func testInTransactionInsideInDatabaseIsNotReentrant() {
// var success = false
// assertNoError {
// try dbQueue.inDatabase { db in
// try self.dbQueue.inTransaction { db in
// success = true
// return .Commit
// }
// }
// }
// XCTAssertTrue(success)
// }
// CRASH TEST: this test must crash
// func testInTransactionIsNotReentrant() {
// dbQueue.inTransaction { db in
+2 -5
View File
@@ -208,11 +208,8 @@ public final class DatabaseQueue {
}
func inQueue<R>(block: () throws -> R) rethrows -> R {
if databaseQueueID == dispatch_get_specific(DatabaseQueue.databaseQueueIDKey) {
return try block()
} else {
return try DatabaseQueue.dispatchSync(queue, block: block)
}
assert(databaseQueueID != dispatch_get_specific(DatabaseQueue.databaseQueueIDKey), "DatabaseQueue.inDatabase(_:) or DatabaseQueue.inTransaction(_:) was called reentrantly, which would lead to a deadlock.")
return try DatabaseQueue.dispatchSync(queue, block: block)
}
// A function declared as rethrows that synchronously executes a throwing