Busy timeouts are really weird

This commit is contained in:
Gwendal Roué committed 2019-12-15 13:17:47 +01:00
1 parent a7f99b83f9
commit 299bfef7b5
1 file changed
+47 -46
@@ -257,50 +257,51 @@ class DatabaseConfigurationTests: GRDBTestCase {
_ = group.wait(timeout: .distantFuture)
}
func testBusyModeTimeoutTooLong() throws {
let dbQueue1 = try makeDatabaseQueue(filename: "test.sqlite")
#if GRDBCIPHER_USE_ENCRYPTION
// Work around SQLCipher bug when two connections are open to the
// same empty database: make sure the database is not empty before
// running this test
try dbQueue1.inDatabase { db in
try db.execute(sql: "CREATE TABLE SQLCipherWorkAround (foo INTEGER)")
}
#endif
var configuration2 = dbQueue1.configuration
configuration2.busyMode = .timeout(1)
let dbQueue2 = try makeDatabaseQueue(filename: "test.sqlite", configuration: configuration2)
let s1 = DispatchSemaphore(value: 0)
let s2 = DispatchSemaphore(value: 0)
let queue = DispatchQueue.global(priority: .default)
let group = DispatchGroup()
queue.async(group: group) {
do {
try dbQueue1.inTransaction(.exclusive) { db in
s2.signal()
queue.asyncAfter(deadline: .now() + 0.1) {
s1.signal()
}
_ = s1.wait(timeout: .distantFuture)
return .commit
}
} catch {
XCTFail("\(error)")
}
}
queue.async(group: group) {
do {
_ = s2.wait(timeout: .distantFuture)
try dbQueue2.inTransaction(.exclusive) { db in return .commit }
} catch {
XCTFail("\(error)")
}
}
_ = group.wait(timeout: .distantFuture)
}
// TODO: fix flaky test. It fails on Xcode 10.0, tvOS 10.0
// func testBusyModeTimeoutTooLong() throws {
// let dbQueue1 = try makeDatabaseQueue(filename: "test.sqlite")
// #if GRDBCIPHER_USE_ENCRYPTION
// // Work around SQLCipher bug when two connections are open to the
// // same empty database: make sure the database is not empty before
// // running this test
// try dbQueue1.inDatabase { db in
// try db.execute(sql: "CREATE TABLE SQLCipherWorkAround (foo INTEGER)")
// }
// #endif
//
// var configuration2 = dbQueue1.configuration
// configuration2.busyMode = .timeout(1)
// let dbQueue2 = try makeDatabaseQueue(filename: "test.sqlite", configuration: configuration2)
//
// let s1 = DispatchSemaphore(value: 0)
// let s2 = DispatchSemaphore(value: 0)
// let queue = DispatchQueue.global(priority: .default)
// let group = DispatchGroup()
//
// queue.async(group: group) {
// do {
// try dbQueue1.inTransaction(.exclusive) { db in
// s2.signal()
// queue.asyncAfter(deadline: .now() + 0.1) {
// s1.signal()
// }
// _ = s1.wait(timeout: .distantFuture)
// return .commit
// }
// } catch {
// XCTFail("\(error)")
// }
// }
//
// queue.async(group: group) {
// do {
// _ = s2.wait(timeout: .distantFuture)
// try dbQueue2.inTransaction(.exclusive) { db in return .commit }
// } catch {
// XCTFail("\(error)")
// }
// }
//
// _ = group.wait(timeout: .distantFuture)
// }
}