mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-28 04:24:20 +00:00
Test that pragma tables are not tracked
This commit is contained in:
1 parent
ed32e44bc2
commit
6ea1e6aeaf
1 file changed
+33
@@ -108,6 +108,39 @@ class ValueObservationTests: GRDBTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
func testPragmaTableOptimization() throws {
|
||||
let dbQueue = try makeDatabaseQueue()
|
||||
try dbQueue.write {
|
||||
try $0.execute(sql: """
|
||||
CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT);
|
||||
""")
|
||||
}
|
||||
|
||||
struct T: TableRecord { }
|
||||
|
||||
// A request that requires a pragma introspection query
|
||||
let request = T.filter(key: 1).asRequest(of: Row.self)
|
||||
|
||||
// Test that no pragma table is included in the observed region.
|
||||
// This optimization helps observation that feed from a single table.
|
||||
var region: DatabaseRegion?
|
||||
let expectation = self.expectation(description: "")
|
||||
let observation = ValueObservation
|
||||
.trackingConstantRegion(request.fetchAll)
|
||||
.handleEvents(willTrackRegion: {
|
||||
region = $0
|
||||
expectation.fulfill()
|
||||
})
|
||||
let observer = observation.start(
|
||||
in: dbQueue,
|
||||
onError: { error in XCTFail("Unexpected error: \(error)") },
|
||||
onChange: { _ in })
|
||||
withExtendedLifetime(observer) {
|
||||
waitForExpectations(timeout: 2, handler: nil)
|
||||
XCTAssertEqual(region!.description, "t(id,name)[1]") // pragma_table_xinfo is NOT tracked
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Snapshot Optimization
|
||||
|
||||
func testDisallowedSnapshotOptimizationWithAsyncScheduler() throws {
|
||||
|
||||
Reference in new issue
Block a user