Skip to content

Commit

Permalink
Add a failing test forr #514
Browse files Browse the repository at this point in the history
  • Loading branch information
groue committed Apr 10, 2019
1 parent be95016 commit a6cbd24
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Tests/GRDBTests/DatabaseRegionObservationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,40 @@ class DatabaseRegionObservationTests: GRDBTestCase {

XCTAssertEqual(count, 1)
}

// Regression test
func testIssue514() throws {
let dbQueue = try makeDatabaseQueue()
try dbQueue.write { db in
try db.create(table: "gallery") { t in
t.column("id", .integer).primaryKey()
t.column("status", .integer)
}
}

struct Gallery: TableRecord { }
let observation = DatabaseRegionObservation(tracking: Gallery.select(Column("id")))

var notificationCount = 0
let observer = try observation.start(in: dbQueue) { _ in
notificationCount += 1
}

try withExtendedLifetime(observer) {
try dbQueue.write { db in
try db.execute(sql: "INSERT INTO gallery (id, status) VALUES (NULL, 0)")
}
XCTAssertEqual(notificationCount, 1)

try dbQueue.write { db in
try db.execute(sql: "UPDATE gallery SET status = 1")
}
XCTAssertEqual(notificationCount, 1) // status is not observed

try dbQueue.write { db in
try db.execute(sql: "DELETE FROM gallery")
}
XCTAssertEqual(notificationCount, 2)
}
}
}

0 comments on commit a6cbd24

Please sign in to comment.