Skip to content

Commit 9dd8b2c

Browse files
committed
Add failing test for task locals access from unsafeRead (#1793)
1 parent c5ac6cd commit 9dd8b2c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Tests/GRDBTests/DatabaseReaderTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,23 @@ class DatabaseReaderTests : GRDBTestCase {
363363
#endif
364364
}
365365

366+
func testUnsafeReadCanAccessTaskLocal() async throws {
367+
func test(_ dbReader: some DatabaseReader) async throws {
368+
let expectedUUID = UUID()
369+
let dbUUID = try await $localUUID.withValue(expectedUUID) {
370+
try await dbReader.unsafeRead { db in localUUID }
371+
}
372+
XCTAssertEqual(dbUUID, expectedUUID)
373+
}
374+
375+
try await test(makeDatabaseQueue())
376+
try await test(makeDatabasePool())
377+
try await test(makeDatabasePool().makeSnapshot())
378+
#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER)
379+
try await test(makeDatabasePool().makeSnapshotPool())
380+
#endif
381+
}
382+
366383
// MARK: - Task Cancellation
367384

368385
func test_read_is_cancelled_by_Task_cancellation_performed_before_database_access() async throws {

0 commit comments

Comments
 (0)