Skip to content

Commit caab403

Browse files
committed
Failing test for concurrent read on memory warning
1 parent bbe94a9 commit caab403

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Tests/GRDBTests/DatabasePoolReleaseMemoryTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,27 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase {
9393
XCTAssertNotEqual(0, dbPool.numberOfReaders)
9494
}
9595
}
96+
97+
// Regression test for <https://github.com/groue/GRDB.swift/pull/1253#issuecomment-1177166630>
98+
func testDatabasePoolDoesNotPreventConcurrentReadsOnPressureEvent() throws {
99+
let dbPool = try makeDatabasePool()
100+
101+
// Start a read that blocks
102+
let semaphore = DispatchSemaphore(value: 0)
103+
dbPool.asyncRead { _ in
104+
semaphore.wait()
105+
}
106+
107+
// Simulate memory warning.
108+
NotificationCenter.default.post(name: UIApplication.didReceiveMemoryWarningNotification, object: nil)
109+
110+
// Make sure we can read
111+
try dbPool.read { _ in }
112+
113+
// Cleanup
114+
semaphore.signal()
115+
}
116+
96117
#endif
97118

98119
// TODO: fix flaky test

0 commit comments

Comments
 (0)