diff --git a/Examples/RemindersTests/Internal.swift b/Examples/RemindersTests/Internal.swift index a73dc220..6d763a8f 100644 --- a/Examples/RemindersTests/Internal.swift +++ b/Examples/RemindersTests/Internal.swift @@ -12,6 +12,7 @@ import Testing .dependency(\.uuid, .incrementing), .dependencies { try $0.bootstrapDatabase() + try await $0.defaultSyncEngine.start() try $0.defaultDatabase.seedSampleData() try await $0.defaultSyncEngine.sendChanges() }, diff --git a/Examples/SyncUpTests/SyncUpFormTests.swift b/Examples/SyncUpTests/SyncUpFormTests.swift index df6b6c24..c0f60e96 100644 --- a/Examples/SyncUpTests/SyncUpFormTests.swift +++ b/Examples/SyncUpTests/SyncUpFormTests.swift @@ -10,6 +10,7 @@ import Testing @Suite( .dependencies { try $0.bootstrapDatabase() + try await $0.defaultSyncEngine.start() try await $0.defaultDatabase.seedForTests() $0.uuid = .incrementing } diff --git a/Sources/SQLiteData/CloudKit/CloudKitSharing.swift b/Sources/SQLiteData/CloudKit/CloudKitSharing.swift index d36306c8..1b5cd976 100644 --- a/Sources/SQLiteData/CloudKit/CloudKitSharing.swift +++ b/Sources/SQLiteData/CloudKit/CloudKitSharing.swift @@ -133,7 +133,9 @@ recordPrimaryKey: record.primaryKey.rawIdentifier, reason: .recordMetadataNotFound, debugDescription: """ - No sync metadata found for record. Has the record been saved to the database? + No sync metadata found for record. Has the record been saved to the database \ + and synchronized to iCloud? Invoke 'SyncEngine.sendChanges()' to force \ + synchronization. """ ) } diff --git a/Sources/SQLiteData/CloudKit/SyncEngine.swift b/Sources/SQLiteData/CloudKit/SyncEngine.swift index 6f968ce5..33ccf8e1 100644 --- a/Sources/SQLiteData/CloudKit/SyncEngine.swift +++ b/Sources/SQLiteData/CloudKit/SyncEngine.swift @@ -91,7 +91,7 @@ privateTables: repeat (each T2).Type, containerIdentifier: String? = nil, defaultZone: CKRecordZone = CKRecordZone(zoneName: "co.pointfree.SQLiteData.defaultZone"), - startImmediately: Bool = true, + startImmediately: Bool? = nil, delegate: (any SyncEngineDelegate)? = nil, logger: Logger = isTesting ? Logger(.disabled) : Logger(subsystem: "SQLiteData", category: "CloudKit") @@ -152,7 +152,7 @@ privateTables: allPrivateTables ) try setUpSyncEngine() - if startImmediately { + if startImmediately ?? !isTesting { _ = try start() } return @@ -201,7 +201,7 @@ privateTables: allPrivateTables ) try setUpSyncEngine() - if startImmediately { + if startImmediately ?? !isTesting { _ = try start() } } @@ -1167,14 +1167,17 @@ } func open(_: some SynchronizableTable) async -> CKRecord? { let row = - withErrorReporting(.sqliteDataCloudKitFailure) { - try userDatabase.read { db in - try T + await withErrorReporting(.sqliteDataCloudKitFailure) { + // NB: Fake 'sending' result. + nonisolated(unsafe) var result: T.QueryOutput? + try await userDatabase.read { db in + result = try T .where { #sql("\($0.primaryKey) = \(bind: metadata.recordPrimaryKey)") } .fetchOne(db) } + return result } ?? nil guard let row diff --git a/Tests/SQLiteDataTests/CloudKitTests/SharingTests.swift b/Tests/SQLiteDataTests/CloudKitTests/SharingTests.swift index 7fff8667..9d6705f4 100644 --- a/Tests/SQLiteDataTests/CloudKitTests/SharingTests.swift +++ b/Tests/SQLiteDataTests/CloudKitTests/SharingTests.swift @@ -307,14 +307,14 @@ """ } assertInlineSnapshot(of: error, as: .customDump) { - """ + #""" SyncEngine.SharingError( recordTableName: "remindersLists", recordPrimaryKey: "1", reason: .recordMetadataNotFound, - debugDescription: "No sync metadata found for record. Has the record been saved to the database?" + debugDescription: "No sync metadata found for record. Has the record been saved to the database and synchronized to iCloud? Invoke \'SyncEngine.sendChanges()\' to force synchronization." ) - """ + """# } }