Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/apple/swift-collections", from: "1.0.0"),
.package(url: "https://github.com/groue/GRDB.swift", from: "7.6.0"),
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras", branch: "task-local-test-trait"),
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.3.3"),
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.9.0"),
.package(url: "https://github.com/pointfreeco/swift-perception", from: "2.0.0"),
Expand Down Expand Up @@ -69,6 +69,7 @@ let package = Package(
dependencies: [
"SQLiteData",
.product(name: "ConcurrencyExtras", package: "swift-concurrency-extras"),
.product(name: "ConcurrencyExtrasTestSupport", package: "swift-concurrency-extras"),
.product(name: "CustomDump", package: "swift-custom-dump"),
.product(name: "Dependencies", package: "swift-dependencies"),
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
Expand Down
11 changes: 7 additions & 4 deletions Tests/SQLiteDataTests/CloudKitTests/AccountLifecycleTests.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#if canImport(CloudKit)
import ConcurrencyExtrasTestSupport
import CloudKit
import CustomDump
import Foundation
Expand Down Expand Up @@ -38,7 +39,8 @@
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test(.accountStatus(.noAccount)) func signInUploadsLocalRecordsToCloudKit() async throws {
@Test(.taskLocal(_$accountStatus, .noAccount))
func signInUploadsLocalRecordsToCloudKit() async throws {
try await userDatabase.userWrite { db in
try db.seed {
RemindersList(id: 1, title: "Personal")
Expand Down Expand Up @@ -367,7 +369,8 @@
_ = try syncEngine.modifyRecords(scope: .shared, saving: [share, remindersListRecord])
let freshShare = try syncEngine.shared.database.record(for: share.recordID) as! CKShare
let freshRemindersListRecord = try syncEngine.shared.database.record(
for: remindersListRecord.recordID)
for: remindersListRecord.recordID
)

try await syncEngine
.acceptShare(
Expand Down Expand Up @@ -604,8 +607,8 @@

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test(
.accountStatus(.noAccount),
.prepareDatabase { userDatabase in
.taskLocal(_$accountStatus, .noAccount),
.taskLocal(_$prepareDatabase) { userDatabase in
try await userDatabase.write { db in
try db.seed {
RemindersList(id: 1, title: "Personal")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#if canImport(CloudKit)
import CloudKit
import ConcurrencyExtras
import ConcurrencyExtrasTestSupport
import CustomDump
import InlineSnapshotTesting
import OrderedCollections
Expand All @@ -11,7 +12,7 @@

extension BaseCloudKitTests {
@MainActor
@Suite(.attachMetadatabase(true))
@Suite(.taskLocal(_$attachMetadatabase, false))
final class AttachedMetadatabaseTests: BaseCloudKitTests, @unchecked Sendable {
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func basics() async throws {
Expand Down
5 changes: 3 additions & 2 deletions Tests/SQLiteDataTests/CloudKitTests/MergeConflictTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if canImport(CloudKit)
import CloudKit
import ConcurrencyExtrasTestSupport
import CustomDump
import Foundation
import InlineSnapshotTesting
Expand All @@ -11,8 +12,8 @@

extension BaseCloudKitTests {
@MainActor
@Suite(.printTimestamps) final class MergeConflictTests: BaseCloudKitTests, @unchecked Sendable
{
@Suite(.taskLocal(CKRecord._$printTimestamps, true))
final class MergeConflictTests: BaseCloudKitTests, @unchecked Sendable {
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func merge_clientRecordUpdatedBeforeServerRecord() async throws {
try await userDatabase.userWrite { db in
Expand Down
5 changes: 3 additions & 2 deletions Tests/SQLiteDataTests/CloudKitTests/MetadataTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if canImport(CloudKit)
import CloudKit
import ConcurrencyExtrasTestSupport
import CustomDump
import SQLiteDataTestSupport
import Foundation
Expand Down Expand Up @@ -623,7 +624,7 @@
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test(.attachMetadatabase(true))
@Test(.taskLocal(_$attachMetadatabase, true))
func observation() async throws {
let remindersList = RemindersList(id: 1, title: "Personal")
try await userDatabase.userWrite { db in
Expand Down Expand Up @@ -652,7 +653,7 @@
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test(.attachMetadatabase(true))
@Test(.taskLocal(_$attachMetadatabase, true))
func observation_GeneratedColumn() async throws {
let remindersList = RemindersList(id: 1, title: "Personal")
try await userDatabase.userWrite { db in
Expand Down
3 changes: 2 additions & 1 deletion Tests/SQLiteDataTests/CloudKitTests/NewTableSyncTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if canImport(CloudKit)
import CloudKit
import ConcurrencyExtrasTestSupport
import CustomDump
import SQLiteDataTestSupport
import Foundation
Expand All @@ -11,7 +12,7 @@
extension BaseCloudKitTests {
@MainActor
@Suite(
.prepareDatabase { userDatabase in
.taskLocal(_$prepareDatabase) { userDatabase in
try await userDatabase.userWrite { db in
try db.seed {
RemindersList(id: 1, title: "Personal")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if canImport(CloudKit)
import CloudKit
import ConcurrencyExtrasTestSupport
import CustomDump
import Foundation
import InlineSnapshotTesting
Expand Down Expand Up @@ -264,7 +265,10 @@
}

@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test(.printTimestamps(true), .printRecordChangeTag)
@Test(
.taskLocal(CKRecord._$printRecordChangeTag, true),
.taskLocal(CKRecord._$printTimestamps, true)
)
func editBetweenBatchAndSentRecordZoneChanges() async throws {
try await userDatabase.userWrite { db in
try db.seed {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if canImport(CloudKit)
import CloudKit
import ConcurrencyExtrasTestSupport
import CustomDump
import DependenciesTestSupport
import Foundation
Expand All @@ -14,7 +15,7 @@
final class SyncEngineDelegateTests: BaseCloudKitTests, @unchecked Sendable {
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)

@Test(.syncEngineDelegate(MyDelegate()))
@Test(.taskLocal(_$syncEngineDelegate, MyDelegate()))
func accountChanged() async throws {
try await userDatabase.userWrite { db in
try db.seed {
Expand Down Expand Up @@ -173,7 +174,7 @@
try await syncEngine.processPendingDatabaseChanges(scope: .private)
}

@Test(.syncEngineDelegate(DefaultImplementationDelegate()))
@Test(.taskLocal(_$syncEngineDelegate, DefaultImplementationDelegate()))
func accountChanged_DefaultImplementation() async throws {
try await userDatabase.userWrite { db in
try db.seed {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if canImport(CloudKit)
import CloudKit
import ConcurrencyExtrasTestSupport
import DependenciesTestSupport
import InlineSnapshotTesting
import SQLiteDataTestSupport
Expand All @@ -16,8 +17,7 @@
@MainActor
@Suite
final class SyncEngineLifecycleTests_ImmediatelyStarted: BaseCloudKitTests,
@unchecked
Sendable
@unchecked Sendable
{
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test func stopAndReStart() async throws {
Expand Down Expand Up @@ -581,7 +581,7 @@
// * Start sync engine
// * Verify that data is sent to CloudKit database and cached locally.
@available(iOS 17, macOS 14, tvOS 17, watchOS 10, *)
@Test(.startImmediately(false)) func writeAndThenStart() async throws {
@Test(.taskLocal(_$startImmediately, false)) func writeAndThenStart() async throws {
try await userDatabase.userWrite { db in
try db.seed {
RemindersList(id: 1, title: "Personal")
Expand Down
17 changes: 8 additions & 9 deletions Tests/SQLiteDataTests/Internal/BaseCloudKitTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#if canImport(CloudKit)
import Clocks
import CloudKit
import ConcurrencyExtrasTestSupport
import DependenciesTestSupport
import OrderedCollections
import SQLiteData
Expand All @@ -15,7 +16,7 @@
$0.continuousClock = TestClock<Duration>()
$0.dataManager = InMemoryDataManager()
},
.attachMetadatabase(false)
.taskLocal(_$attachMetadatabase, false)
)
class BaseCloudKitTests: @unchecked Sendable {
let userDatabase: UserDatabase
Expand Down Expand Up @@ -49,14 +50,14 @@
self.userDatabase = UserDatabase(
database: try SQLiteDataTests.database(
containerIdentifier: testContainerIdentifier,
attachMetadatabase: _AttachMetadatabaseTrait.attachMetadatabase
attachMetadatabase: attachMetadatabase
)
)
try await _PrepareDatabaseTrait.prepareDatabase(userDatabase)
try await prepareDatabase(userDatabase)
let privateDatabase = MockCloudDatabase(databaseScope: .private)
let sharedDatabase = MockCloudDatabase(databaseScope: .shared)
let container = MockCloudContainer(
accountStatus: _AccountStatusScope.accountStatus,
accountStatus: accountStatus,
containerIdentifier: testContainerIdentifier,
privateCloudDatabase: privateDatabase,
sharedCloudDatabase: sharedDatabase
Expand All @@ -67,7 +68,7 @@
_syncEngine = try await SyncEngine(
container: container,
userDatabase: self.userDatabase,
delegate: _SyncEngineDelegateTrait.syncEngineDelegate,
delegate: syncEngineDelegate,
tables: Reminder.self,
RemindersList.self,
RemindersListAsset.self,
Expand All @@ -81,11 +82,9 @@
ModelC.self,
ScopedModel.self,
privateTables: RemindersListPrivate.self,
startImmediately: _StartImmediatelyTrait.startImmediately
startImmediately: startImmediately
)
if _StartImmediatelyTrait.startImmediately,
_AccountStatusScope.accountStatus == .available
{
if startImmediately, accountStatus == .available {
await syncEngine.handleEvent(
.accountChange(changeType: .signIn(currentUser: currentUserRecordID)),
syncEngine: syncEngine.private
Expand Down
10 changes: 8 additions & 2 deletions Tests/SQLiteDataTests/Internal/CloudKit+CustomDump.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@
}

extension CKRecord {
@TaskLocal static var printTimestamps = false
@TaskLocal static var printRecordChangeTag = false
static let _$printTimestamps = TaskLocal(wrappedValue: false)
static let _$printRecordChangeTag = TaskLocal(wrappedValue: false)
static var printTimestamps: Bool {
_$printTimestamps.get()
}
static var printRecordChangeTag: Bool {
_$printRecordChangeTag.get()
}
}

@available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
Expand Down
Loading