From 9dd8b2cef772596eed2b2b888db47eec26f58205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 19 Jul 2025 10:31:13 +0200 Subject: [PATCH] Add failing test for task locals access from unsafeRead (#1793) --- Tests/GRDBTests/DatabaseReaderTests.swift | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Tests/GRDBTests/DatabaseReaderTests.swift b/Tests/GRDBTests/DatabaseReaderTests.swift index 92f6a35c3..90053f915 100644 --- a/Tests/GRDBTests/DatabaseReaderTests.swift +++ b/Tests/GRDBTests/DatabaseReaderTests.swift @@ -363,6 +363,23 @@ class DatabaseReaderTests : GRDBTestCase { #endif } + func testUnsafeReadCanAccessTaskLocal() async throws { + func test(_ dbReader: some DatabaseReader) async throws { + let expectedUUID = UUID() + let dbUUID = try await $localUUID.withValue(expectedUUID) { + try await dbReader.unsafeRead { db in localUUID } + } + XCTAssertEqual(dbUUID, expectedUUID) + } + + try await test(makeDatabaseQueue()) + try await test(makeDatabasePool()) + try await test(makeDatabasePool().makeSnapshot()) +#if SQLITE_ENABLE_SNAPSHOT || (!GRDBCUSTOMSQLITE && !GRDBCIPHER) + try await test(makeDatabasePool().makeSnapshotPool()) +#endif + } + // MARK: - Task Cancellation func test_read_is_cancelled_by_Task_cancellation_performed_before_database_access() async throws {