From 8e84beee36fef93f27d58e4ce71aec08b88ba214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Tue, 1 Feb 2022 10:08:24 +0100 Subject: [PATCH] Fix Swift 5.6 warnings --- Tests/GRDBTests/GRDBTestCase.swift | 5 +++ Tests/GRDBTests/ValueObservationTests.swift | 37 ++++++++++----------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Tests/GRDBTests/GRDBTestCase.swift b/Tests/GRDBTests/GRDBTestCase.swift index f93e8ab7c..f34adc0c7 100644 --- a/Tests/GRDBTests/GRDBTestCase.swift +++ b/Tests/GRDBTests/GRDBTestCase.swift @@ -258,3 +258,8 @@ public struct AnyValueReducer: ValueReducer { __value(fetched) } } + +#if swift(>=5.5) && canImport(_Concurrency) +// Assume this is correct :-/ +extension XCTestExpectation: @unchecked Sendable { } +#endif diff --git a/Tests/GRDBTests/ValueObservationTests.swift b/Tests/GRDBTests/ValueObservationTests.swift index 2da175bdf..5831f963d 100644 --- a/Tests/GRDBTests/ValueObservationTests.swift +++ b/Tests/GRDBTests/ValueObservationTests.swift @@ -704,12 +704,11 @@ class ValueObservationTests: GRDBTestCase { try await writer.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } let cancellationExpectation = expectation(description: "cancelled") - let observation = ValueObservation - .trackingConstantRegion(Table("t").fetchCount) - .handleEvents(didCancel: { cancellationExpectation.fulfill() }) - let task = Task { () -> [Int] in var counts: [Int] = [] + let observation = ValueObservation + .trackingConstantRegion(Table("t").fetchCount) + .handleEvents(didCancel: { cancellationExpectation.fulfill() }) for try await count in try observation.values(in: writer).prefix(while: { $0 < 3 }) { counts.append(count) @@ -740,12 +739,11 @@ class ValueObservationTests: GRDBTestCase { try await writer.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } let cancellationExpectation = expectation(description: "cancelled") - let observation = ValueObservation - .trackingConstantRegion(Table("t").fetchCount) - .handleEvents(didCancel: { cancellationExpectation.fulfill() }) - let task = Task { @MainActor () -> [Int] in var counts: [Int] = [] + let observation = ValueObservation + .trackingConstantRegion(Table("t").fetchCount) + .handleEvents(didCancel: { cancellationExpectation.fulfill() }) for try await count in try observation.values(in: writer, scheduling: .immediate).prefix(while: { $0 < 3 }) { counts.append(count) @@ -776,12 +774,11 @@ class ValueObservationTests: GRDBTestCase { try await writer.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } let cancellationExpectation = expectation(description: "cancelled") - let observation = ValueObservation - .trackingConstantRegion(Table("t").fetchCount) - .handleEvents(didCancel: { cancellationExpectation.fulfill() }) - let task = Task { () -> [Int] in var counts: [Int] = [] + let observation = ValueObservation + .trackingConstantRegion(Table("t").fetchCount) + .handleEvents(didCancel: { cancellationExpectation.fulfill() }) for try await count in observation.values(in: writer) { counts.append(count) @@ -816,12 +813,12 @@ class ValueObservationTests: GRDBTestCase { try await writer.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } let cancellationExpectation = expectation(description: "cancelled") - let observation = ValueObservation - .trackingConstantRegion(Table("t").fetchCount) - .handleEvents(didCancel: { cancellationExpectation.fulfill() }) let task = Task { @MainActor () -> [Int] in var counts: [Int] = [] + let observation = ValueObservation + .trackingConstantRegion(Table("t").fetchCount) + .handleEvents(didCancel: { cancellationExpectation.fulfill() }) for try await count in observation.values(in: writer, scheduling: .immediate) { counts.append(count) @@ -851,22 +848,22 @@ class ValueObservationTests: GRDBTestCase { // We need something to change try await writer.write { try $0.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)") } - let observation = ValueObservation.trackingConstantRegion(Table("t").fetchCount) - let cancellationExpectation = expectation(description: "cancelled") - let cancelledObservation = observation.handleEvents(didCancel: { - cancellationExpectation.fulfill() - }) // Launch a task that we'll cancel let cancelledTask = Task { // Loops until cancelled + let observation = ValueObservation.trackingConstantRegion(Table("t").fetchCount) + let cancelledObservation = observation.handleEvents(didCancel: { + cancellationExpectation.fulfill() + }) for try await _ in cancelledObservation.values(in: writer) { } return "cancelled loop" } // Lanch the task that cancels Task { + let observation = ValueObservation.trackingConstantRegion(Table("t").fetchCount) for try await count in observation.values(in: writer) { if count == 3 { cancelledTask.cancel()