diff --git a/GRDB Tests/Public/Core/Database/DatabaseTests.swift b/GRDB Tests/Public/Core/Database/DatabaseTests.swift index 1f833dfee..853543ae0 100644 --- a/GRDB Tests/Public/Core/Database/DatabaseTests.swift +++ b/GRDB Tests/Public/Core/Database/DatabaseTests.swift @@ -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 diff --git a/GRDB/Core/DatabaseQueue.swift b/GRDB/Core/DatabaseQueue.swift index 0bea547ba..8c83ae8f4 100644 --- a/GRDB/Core/DatabaseQueue.swift +++ b/GRDB/Core/DatabaseQueue.swift @@ -208,11 +208,8 @@ public final class DatabaseQueue { } func inQueue(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