Skip to content

Commit 32ca8df

Browse files
Don't startImmediately in tests (#375)
* Update start behavior for sync engine. * wip * wip * wip --------- Co-authored-by: Brandon Williams <mbrandonw@hey.com>
1 parent 2901a70 commit 32ca8df

5 files changed

Lines changed: 17 additions & 10 deletions

File tree

Examples/RemindersTests/Internal.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Testing
1212
.dependency(\.uuid, .incrementing),
1313
.dependencies {
1414
try $0.bootstrapDatabase()
15+
try await $0.defaultSyncEngine.start()
1516
try $0.defaultDatabase.seedSampleData()
1617
try await $0.defaultSyncEngine.sendChanges()
1718
},

Examples/SyncUpTests/SyncUpFormTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Testing
1010
@Suite(
1111
.dependencies {
1212
try $0.bootstrapDatabase()
13+
try await $0.defaultSyncEngine.start()
1314
try await $0.defaultDatabase.seedForTests()
1415
$0.uuid = .incrementing
1516
}

Sources/SQLiteData/CloudKit/CloudKitSharing.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@
133133
recordPrimaryKey: record.primaryKey.rawIdentifier,
134134
reason: .recordMetadataNotFound,
135135
debugDescription: """
136-
No sync metadata found for record. Has the record been saved to the database?
136+
No sync metadata found for record. Has the record been saved to the database \
137+
and synchronized to iCloud? Invoke 'SyncEngine.sendChanges()' to force \
138+
synchronization.
137139
"""
138140
)
139141
}

Sources/SQLiteData/CloudKit/SyncEngine.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
privateTables: repeat (each T2).Type,
9292
containerIdentifier: String? = nil,
9393
defaultZone: CKRecordZone = CKRecordZone(zoneName: "co.pointfree.SQLiteData.defaultZone"),
94-
startImmediately: Bool = true,
94+
startImmediately: Bool? = nil,
9595
delegate: (any SyncEngineDelegate)? = nil,
9696
logger: Logger = isTesting
9797
? Logger(.disabled) : Logger(subsystem: "SQLiteData", category: "CloudKit")
@@ -152,7 +152,7 @@
152152
privateTables: allPrivateTables
153153
)
154154
try setUpSyncEngine()
155-
if startImmediately {
155+
if startImmediately ?? !isTesting {
156156
_ = try start()
157157
}
158158
return
@@ -201,7 +201,7 @@
201201
privateTables: allPrivateTables
202202
)
203203
try setUpSyncEngine()
204-
if startImmediately {
204+
if startImmediately ?? !isTesting {
205205
_ = try start()
206206
}
207207
}
@@ -1167,14 +1167,17 @@
11671167
}
11681168
func open<T>(_: some SynchronizableTable<T>) async -> CKRecord? {
11691169
let row =
1170-
withErrorReporting(.sqliteDataCloudKitFailure) {
1171-
try userDatabase.read { db in
1172-
try T
1170+
await withErrorReporting(.sqliteDataCloudKitFailure) {
1171+
// NB: Fake 'sending' result.
1172+
nonisolated(unsafe) var result: T.QueryOutput?
1173+
try await userDatabase.read { db in
1174+
result = try T
11731175
.where {
11741176
#sql("\($0.primaryKey) = \(bind: metadata.recordPrimaryKey)")
11751177
}
11761178
.fetchOne(db)
11771179
}
1180+
return result
11781181
}
11791182
?? nil
11801183
guard let row

Tests/SQLiteDataTests/CloudKitTests/SharingTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,14 +307,14 @@
307307
"""
308308
}
309309
assertInlineSnapshot(of: error, as: .customDump) {
310-
"""
310+
#"""
311311
SyncEngine.SharingError(
312312
recordTableName: "remindersLists",
313313
recordPrimaryKey: "1",
314314
reason: .recordMetadataNotFound,
315-
debugDescription: "No sync metadata found for record. Has the record been saved to the database?"
315+
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."
316316
)
317-
"""
317+
"""#
318318
}
319319
}
320320

0 commit comments

Comments
 (0)