mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-29 04:24:21 +00:00
Test that DatabaseSnapshotPool can be used from ValueObservation
This commit is contained in:
1 parent
79d4db7827
commit
e4c5cc3451
1 file changed
+26
-1
@@ -313,7 +313,7 @@ class ValueObservationTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Snapshot Optimization
|
||||
|
||||
func testDisallowedSnapshotOptimizationWithAsyncScheduler() throws {
|
||||
@@ -496,6 +496,31 @@ class ValueObservationTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Snapshot Observation
|
||||
|
||||
func testDatabaseSnapshotPoolObservation() throws {
|
||||
let dbPool = try makeDatabasePool()
|
||||
try dbPool.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") }
|
||||
|
||||
let expectation = XCTestExpectation()
|
||||
expectation.assertForOverFulfill = false
|
||||
|
||||
let observation = ValueObservation.trackingConstantRegion { db in
|
||||
try db.registerAccess(to: Table("t"))
|
||||
expectation.fulfill()
|
||||
return try DatabaseSnapshotPool(db)
|
||||
}
|
||||
|
||||
let recorder = observation.record(in: dbPool)
|
||||
wait(for: [expectation], timeout: 5)
|
||||
try dbPool.write { try $0.execute(sql: "INSERT INTO t DEFAULT VALUES") }
|
||||
|
||||
let results = try wait(for: recorder.next(2), timeout: 5)
|
||||
XCTAssertEqual(results.count, 2)
|
||||
try XCTAssertEqual(results[0].read { try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM t")! }, 0)
|
||||
try XCTAssertEqual(results[1].read { try Int.fetchOne($0, sql: "SELECT COUNT(*) FROM t")! }, 1)
|
||||
}
|
||||
|
||||
// MARK: - Cancellation
|
||||
|
||||
func testCancellableLifetime() throws {
|
||||
|
||||
Reference in new issue
Block a user