Failing test for concurrent read on memory warning

This commit is contained in:
Gwendal Roué committed 2022-07-09 13:31:15 +02:00
1 parent bbe94a9607
commit caab403282
1 file changed
+21
@@ -93,6 +93,27 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
XCTAssertNotEqual(0, dbPool.numberOfReaders)
}
}
// Regression test for <https://github.com/groue/GRDB.swift/pull/1253#issuecomment-1177166630>
func testDatabasePoolDoesNotPreventConcurrentReadsOnPressureEvent() throws {
let dbPool = try makeDatabasePool()
// Start a read that blocks
let semaphore = DispatchSemaphore(value: 0)
dbPool.asyncRead { _ in
semaphore.wait()
}
// Simulate memory warning.
NotificationCenter.default.post(name: UIApplication.didReceiveMemoryWarningNotification, object: nil)
// Make sure we can read
try dbPool.read { _ in }
// Cleanup
semaphore.signal()
}
#endif
// TODO: fix flaky test