From a6cbd242e6a776aa225dd44abb4d85d4c4b8d94f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Wed, 10 Apr 2019 19:29:50 +0200 Subject: [PATCH] Add a failing test forr #514 --- .../DatabaseRegionObservationTests.swift | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Tests/GRDBTests/DatabaseRegionObservationTests.swift b/Tests/GRDBTests/DatabaseRegionObservationTests.swift index 7ca3e1a9b0..e6d18cb2ed 100644 --- a/Tests/GRDBTests/DatabaseRegionObservationTests.swift +++ b/Tests/GRDBTests/DatabaseRegionObservationTests.swift @@ -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) + } + } }