From 4ab8ac8d3f5a2b7507cdabc3b3b0b00db34d2a6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Thu, 1 Jun 2023 19:53:34 +0200 Subject: [PATCH] Failing test for #1383 (async version) --- Tests/GRDBTests/ValueObservationTests.swift | 30 +++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Tests/GRDBTests/ValueObservationTests.swift b/Tests/GRDBTests/ValueObservationTests.swift index d6697df2c..ebfd2a281 100644 --- a/Tests/GRDBTests/ValueObservationTests.swift +++ b/Tests/GRDBTests/ValueObservationTests.swift @@ -1175,4 +1175,34 @@ class ValueObservationTests: GRDBTestCase { }) } } + + // Regression test for + func testIssue1383_async() throws { + do { + let dbPool = try makeDatabasePool(filename: "test") + try dbPool.writeWithoutTransaction { db in + try db.execute(sql: "CREATE TABLE t(a)") + try db.checkpoint(.truncate) + } + } + + do { + let dbPool = try makeDatabasePool(filename: "test") + let observation = ValueObservation.tracking(Table("t").fetchCount) + let expectation = self.expectation(description: "completion") + expectation.assertForOverFulfill = false + let cancellable = observation.start( + in: dbPool, + onError: { error in + XCTFail("Unexpected error \(error)") + expectation.fulfill() + }, + onChange: { _ in + expectation.fulfill() + }) + withExtendedLifetime(cancellable) { _ in + wait(for: [expectation], timeout: 2) + } + } + } }