From caab403282db13cf1c9049c066afa65901007e68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 9 Jul 2022 13:31:15 +0200 Subject: [PATCH] Failing test for concurrent read on memory warning --- .../DatabasePoolReleaseMemoryTests.swift | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Tests/GRDBTests/DatabasePoolReleaseMemoryTests.swift b/Tests/GRDBTests/DatabasePoolReleaseMemoryTests.swift index c3219279e..0b988c147 100644 --- a/Tests/GRDBTests/DatabasePoolReleaseMemoryTests.swift +++ b/Tests/GRDBTests/DatabasePoolReleaseMemoryTests.swift @@ -93,6 +93,27 @@ class DatabasePoolReleaseMemoryTests: GRDBTestCase { XCTAssertNotEqual(0, dbPool.numberOfReaders) } } + + // Regression test for + 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