More DatabaseSnapshotPool tests

This commit is contained in:
Gwendal Roué committed 2022-11-17 21:56:01 +01:00
1 parent b1770e89b7
commit 79d4db7827
6 files changed
+74 -5

No files matched your search

+3 -1
View File
@@ -162,7 +162,9 @@ public final class DatabaseSnapshotPool {
})
// Get WAL snapshot
walSnapshot = try db.isolated(readOnly: true) { try WALSnapshot(db) }
walSnapshot = try db.isolated(readOnly: true) {
try WALSnapshot(db)
}
// Create first connection that will keep the WALSnapshot alive.
try readerPool!.get { _ in }
-2
View File
@@ -42,8 +42,6 @@ final class WALSnapshot: Sendable {
let sqliteSnapshot: UnsafeMutablePointer<sqlite3_snapshot>
/// Returns nil if `SQLITE_ENABLE_SNAPSHOT` is not enabled, or if an
/// error occurs.
init(_ db: Database) throws {
var sqliteSnapshot: UnsafeMutablePointer<sqlite3_snapshot>?
let code = withUnsafeMutablePointer(to: &sqliteSnapshot) {
@@ -44,6 +44,10 @@ class DatabaseReaderReadPublisherTests : XCTestCase {
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabaseQueue(path: $0)) }
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)) }
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)).makeSnapshot() }
#if (compiler(<5.7.1) && (os(macOS) || targetEnvironment(macCatalyst))) || GRDBCIPHER || (GRDBCUSTOMSQLITE && !SQLITE_ENABLE_SNAPSHOT)
#else
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)).makeSnapshotPool() }
#endif
}
// MARK: -
@@ -146,6 +150,10 @@ class DatabaseReaderReadPublisherTests : XCTestCase {
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0).makeSnapshot() }
#if (compiler(<5.7.1) && (os(macOS) || targetEnvironment(macCatalyst))) || GRDBCIPHER || (GRDBCUSTOMSQLITE && !SQLITE_ENABLE_SNAPSHOT)
#else
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0).makeSnapshotPool() }
#endif
}
// MARK: -
@@ -183,6 +191,10 @@ class DatabaseReaderReadPublisherTests : XCTestCase {
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabaseQueue(path: $0)) }
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)) }
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)).makeSnapshot() }
#if (compiler(<5.7.1) && (os(macOS) || targetEnvironment(macCatalyst))) || GRDBCIPHER || (GRDBCUSTOMSQLITE && !SQLITE_ENABLE_SNAPSHOT)
#else
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)).makeSnapshotPool() }
#endif
}
// MARK: -
@@ -220,6 +232,10 @@ class DatabaseReaderReadPublisherTests : XCTestCase {
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabaseQueue(path: $0)) }
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)) }
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)).makeSnapshot() }
#if (compiler(<5.7.1) && (os(macOS) || targetEnvironment(macCatalyst))) || GRDBCIPHER || (GRDBCUSTOMSQLITE && !SQLITE_ENABLE_SNAPSHOT)
#else
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)).makeSnapshotPool() }
#endif
}
// MARK: -
@@ -258,6 +274,10 @@ class DatabaseReaderReadPublisherTests : XCTestCase {
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabaseQueue(path: $0)) }
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)) }
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)).makeSnapshot() }
#if (compiler(<5.7.1) && (os(macOS) || targetEnvironment(macCatalyst))) || GRDBCIPHER || (GRDBCUSTOMSQLITE && !SQLITE_ENABLE_SNAPSHOT)
#else
try Test(test).runAtTemporaryDatabasePath { try setUp(DatabasePool(path: $0)).makeSnapshotPool() }
#endif
}
// MARK: -
@@ -283,6 +303,10 @@ class DatabaseReaderReadPublisherTests : XCTestCase {
try Test(test).runAtTemporaryDatabasePath { try DatabaseQueue(path: $0) }
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0) }
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0).makeSnapshot() }
#if (compiler(<5.7.1) && (os(macOS) || targetEnvironment(macCatalyst))) || GRDBCIPHER || (GRDBCUSTOMSQLITE && !SQLITE_ENABLE_SNAPSHOT)
#else
try Test(test).runAtTemporaryDatabasePath { try DatabasePool(path: $0).makeSnapshotPool() }
#endif
}
}
#endif
@@ -40,6 +40,10 @@ class DatabaseAbortedTransactionTests : GRDBTestCase {
try test(makeDatabaseQueue())
try test(makeDatabasePool())
try test(makeDatabasePool().makeSnapshot())
#if (compiler(<5.7.1) && (os(macOS) || targetEnvironment(macCatalyst))) || GRDBCIPHER || (GRDBCUSTOMSQLITE && !SQLITE_ENABLE_SNAPSHOT)
#else
try test(makeDatabasePool().makeSnapshotPool())
#endif
}
func testReadTransactionAbortedByInterruptDoesNotPreventFurtherRead() throws {
@@ -82,6 +86,10 @@ class DatabaseAbortedTransactionTests : GRDBTestCase {
try test(makeDatabaseQueue())
try test(makeDatabasePool())
try test(makeDatabasePool().makeSnapshot())
#if (compiler(<5.7.1) && (os(macOS) || targetEnvironment(macCatalyst))) || GRDBCIPHER || (GRDBCUSTOMSQLITE && !SQLITE_ENABLE_SNAPSHOT)
#else
try test(makeDatabasePool().makeSnapshotPool())
#endif
}
func testWriteTransactionAbortedByInterrupt() throws {
@@ -26,6 +26,12 @@ class DatabaseConfigurationTests: GRDBTestCase {
try pool.makeSnapshot().read { _ in }
XCTAssertEqual(connectionCount, 5)
#if (compiler(<5.7.1) && (os(macOS) || targetEnvironment(macCatalyst))) || GRDBCIPHER || (GRDBCUSTOMSQLITE && !SQLITE_ENABLE_SNAPSHOT)
#else
try pool.makeSnapshotPool().read { _ in }
XCTAssertEqual(connectionCount, 6)
#endif
}
func testPrepareDatabaseError() throws {
@@ -68,6 +74,15 @@ class DatabaseConfigurationTests: GRDBTestCase {
_ = try pool.makeSnapshot()
XCTFail("Expected TestError")
} catch is TestError { }
#if (compiler(<5.7.1) && (os(macOS) || targetEnvironment(macCatalyst))) || GRDBCIPHER || (GRDBCUSTOMSQLITE && !SQLITE_ENABLE_SNAPSHOT)
#else
do {
error = TestError()
_ = try pool.makeSnapshotPool()
XCTFail("Expected TestError")
} catch is TestError { }
#endif
}
}
@@ -54,6 +54,10 @@ class ValueObservationPrintTests: GRDBTestCase {
try test(makeDatabaseQueue(filename: "test", configuration: config))
try test(makeDatabasePool(filename: "test", configuration: config))
try test(makeDatabasePool(filename: "test", configuration: config).makeSnapshot())
#if (compiler(<5.7.1) && (os(macOS) || targetEnvironment(macCatalyst))) || GRDBCIPHER || (GRDBCUSTOMSQLITE && !SQLITE_ENABLE_SNAPSHOT)
#else
try test(makeDatabasePool(filename: "test", configuration: config).makeSnapshotPool())
#endif
}
func test_readonly_success_immediateScheduling() throws {
@@ -88,11 +92,18 @@ class ValueObservationPrintTests: GRDBTestCase {
try test(makeDatabaseQueue(filename: "test", configuration: config))
try test(makeDatabasePool(filename: "test", configuration: config))
try test(makeDatabasePool(filename: "test", configuration: config).makeSnapshot())
#if (compiler(<5.7.1) && (os(macOS) || targetEnvironment(macCatalyst))) || GRDBCIPHER || (GRDBCUSTOMSQLITE && !SQLITE_ENABLE_SNAPSHOT)
#else
try test(makeDatabasePool(filename: "test", configuration: config).makeSnapshotPool())
#endif
}
func test_readonly_failure_asynchronousScheduling() throws {
struct TestError: Error { }
_ = try makeDatabasePool(filename: "test")
let dbPool = try makeDatabasePool(filename: "test")
// workaround Xcode 14.1 compiler (???) bug: database is not in the WAL
// mode unless the pool is used.
try dbPool.write { _ in }
func test(_ dbReader: some DatabaseReader) throws {
let logger = TestStream()
@@ -120,11 +131,18 @@ class ValueObservationPrintTests: GRDBTestCase {
try test(makeDatabaseQueue(filename: "test", configuration: config))
try test(makeDatabasePool(filename: "test", configuration: config))
try test(makeDatabasePool(filename: "test", configuration: config).makeSnapshot())
#if (compiler(<5.7.1) && (os(macOS) || targetEnvironment(macCatalyst))) || GRDBCIPHER || (GRDBCUSTOMSQLITE && !SQLITE_ENABLE_SNAPSHOT)
#else
try test(makeDatabasePool(filename: "test", configuration: config).makeSnapshotPool())
#endif
}
func test_readonly_failure_immediateScheduling() throws {
struct TestError: Error { }
_ = try makeDatabasePool(filename: "test")
let dbPool = try makeDatabasePool(filename: "test")
// workaround Xcode 14.1 compiler (???) bug: database is not in the WAL
// mode unless the pool is used.
try dbPool.write { _ in }
func test(_ dbReader: some DatabaseReader) throws {
let logger = TestStream()
@@ -152,6 +170,10 @@ class ValueObservationPrintTests: GRDBTestCase {
try test(makeDatabaseQueue(filename: "test", configuration: config))
try test(makeDatabasePool(filename: "test", configuration: config))
try test(makeDatabasePool(filename: "test", configuration: config).makeSnapshot())
#if (compiler(<5.7.1) && (os(macOS) || targetEnvironment(macCatalyst))) || GRDBCIPHER || (GRDBCUSTOMSQLITE && !SQLITE_ENABLE_SNAPSHOT)
#else
try test(makeDatabasePool(filename: "test", configuration: config).makeSnapshotPool())
#endif
}
// MARK: - Writeonly