Skip to content

Commit

Permalink
Test async read after async write
Browse files Browse the repository at this point in the history
  • Loading branch information
groue committed Nov 11, 2023
1 parent 7eaf67f commit 8b19c34
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Tests/GRDBTests/DatabaseWriterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,27 @@ class DatabaseWriterTests : GRDBTestCase {
try await test(setup(makeDatabaseQueue()))
try await test(setup(makeDatabasePool()))
}

/// A test related to <https://github.com/groue/GRDB.swift/issues/1456>
@available(iOS 13, macOS 10.15, tvOS 13, watchOS 6, *)
func testAsyncWriteThenRead() async throws {
/// An async read performed after an async write should see the write.
func test(_ dbWriter: some DatabaseWriter) async throws {
try await dbWriter.write { db in
try db.execute(sql: """
CREATE TABLE t (id INTEGER PRIMARY KEY);
INSERT INTO t VALUES (1);
""")
}

let count = try await dbWriter.read { db in
try Table("t").fetchCount(db)
}

XCTAssertEqual(count, 1)
}

try await test(makeDatabaseQueue())
try await test(makeDatabasePool())
}
}

0 comments on commit 8b19c34

Please sign in to comment.