Skip to content

Commit

Permalink
Build in Swift 6 language mode when supported
Browse files Browse the repository at this point in the history
  • Loading branch information
tgoyne committed Aug 27, 2024
1 parent 7ffcc11 commit db56980
Show file tree
Hide file tree
Showing 25 changed files with 1,773 additions and 361 deletions.
6 changes: 6 additions & 0 deletions Realm.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2895,6 +2895,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 3FEC91542A4B59A40044BFF5 /* Static.xcconfig */;
buildSettings = {
SWIFT_VERSION = 6.0;
};
name = Static;
};
Expand All @@ -2909,6 +2910,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 5D660FBD1BE98BEF0021E04F /* RealmSwift.xcconfig */;
buildSettings = {
SWIFT_VERSION = 6.0;
};
name = Static;
};
Expand Down Expand Up @@ -3087,13 +3089,15 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 5D660FBD1BE98BEF0021E04F /* RealmSwift.xcconfig */;
buildSettings = {
SWIFT_VERSION = 6.0;
};
name = Debug;
};
5D660FD31BE98C560021E04F /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 5D660FBD1BE98BEF0021E04F /* RealmSwift.xcconfig */;
buildSettings = {
SWIFT_VERSION = 6.0;
};
name = Release;
};
Expand Down Expand Up @@ -3233,13 +3237,15 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 5D659E6E1BE0398E006515A0 /* Debug.xcconfig */;
buildSettings = {
SWIFT_VERSION = 6.0;
};
name = Debug;
};
E8D89BAD1955FC6D00CF2B9A /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 5D659E6F1BE0398E006515A0 /* Release.xcconfig */;
buildSettings = {
SWIFT_VERSION = 6.0;
};
name = Release;
};
Expand Down
13 changes: 11 additions & 2 deletions Realm/ObjectServerTests/AsyncSyncTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,14 @@ class AsyncAwaitSyncTests: SwiftSyncTestCase {

let configuration = try configuration()
func isolatedOpen(_ actor: isolated CustomExecutorActor) async throws {
#if compiler(<6)
_ = try await Realm(configuration: configuration, actor: actor, downloadBeforeOpen: .always)
#else
_ = try await Realm.open(configuration: configuration, downloadBeforeOpen: .always)
#endif
}


// Try opening the Realm with the Task being cancelled at every possible
// point between executor invocations. This doesn't really test that
// cancellation is *correct*; just that cancellation never results in
Expand Down Expand Up @@ -825,7 +830,7 @@ class AsyncFlexibleSyncTests: SwiftSyncTestCase {
.subscribe(name: "8 or older")
realm.syncSession!.suspend()
let ex = XCTestExpectation(description: "no attempt to re-create subscription, returns immediately")
Task {
Task { @MainActor in
_ = try await realm.objects(SwiftPerson.self)
.where { $0.firstName == name && $0.age >= 8 }
.subscribe(name: "8 or older")
Expand Down Expand Up @@ -875,7 +880,7 @@ class AsyncFlexibleSyncTests: SwiftSyncTestCase {
let user = try await createUser()
var config = user.flexibleSyncConfiguration()
config.objectTypes = [SwiftPerson.self]
let realm = try await Realm(configuration: config, actor: MainActor.shared)
let realm = try await Realm(configuration: config)
let results1 = try await realm.objects(SwiftPerson.self)
.where { $0.firstName == name && $0.age > 8 }.subscribe(waitForSync: .onCreation)
XCTAssertEqual(results1.count, 2)
Expand All @@ -895,7 +900,11 @@ class AsyncFlexibleSyncTests: SwiftSyncTestCase {
let user = try await createUser()
var config = user.flexibleSyncConfiguration()
config.objectTypes = [SwiftPerson.self]
#if compiler(<6)
let realm = try await Realm(configuration: config, actor: CustomGlobalActor.shared)
#else
let realm = try await Realm.open(configuration: config)
#endif
let results1 = try await realm.objects(SwiftPerson.self)
.where { $0.firstName == name && $0.age > 8 }.subscribe(waitForSync: .onCreation)
XCTAssertEqual(results1.count, 2)
Expand Down
50 changes: 31 additions & 19 deletions Realm/ObjectServerTests/CombineSyncTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,27 @@ import RealmTestSupport
import RealmSwiftTestSupport
#endif

extension AnyCancellable {
func store(in lockedSet: Locked<Set<AnyCancellable>>) {
lockedSet.withLock {
self.store(in: &$0)
}
}
}

@available(macOS 13, *)
@objc(CombineSyncTests)
class CombineSyncTests: SwiftSyncTestCase {
override var objectTypes: [ObjectBase.Type] {
[Dog.self, SwiftPerson.self, SwiftHugeSyncObject.self]
}

var subscriptions: Set<AnyCancellable> = []
nonisolated let subscriptions = Locked(Set<AnyCancellable>())
override func tearDown() {
subscriptions.forEach { $0.cancel() }
subscriptions = []
subscriptions.withLock {
$0.forEach { $0.cancel() }
$0 = []
}
super.tearDown()
}

Expand All @@ -62,7 +72,7 @@ class CombineSyncTests: SwiftSyncTestCase {
.sink(receiveCompletion: { @Sendable _ in }) { @Sendable _ in
XCTAssertFalse(Thread.isMainThread)
watchEx1.wrappedValue.fulfill()
}.store(in: &subscriptions)
}.store(in: subscriptions)

collection.watch()
.onOpen {
Expand All @@ -73,7 +83,7 @@ class CombineSyncTests: SwiftSyncTestCase {
.sink(receiveCompletion: { _ in }) { _ in
XCTAssertTrue(Thread.isMainThread)
watchEx2.wrappedValue.fulfill()
}.store(in: &subscriptions)
}.store(in: subscriptions)

for _ in 0..<3 {
wait(for: [watchEx1.wrappedValue, watchEx2.wrappedValue], timeout: 60.0)
Expand Down Expand Up @@ -116,7 +126,7 @@ class CombineSyncTests: SwiftSyncTestCase {
if objectId == objectIds[0] {
watchEx1.wrappedValue.fulfill()
}
}.store(in: &subscriptions)
}.store(in: subscriptions)

collection.watch(filterIds: [objectIds[1]])
.onOpen {
Expand All @@ -134,7 +144,7 @@ class CombineSyncTests: SwiftSyncTestCase {
if objectId == objectIds[1] {
watchEx2.wrappedValue.fulfill()
}
}.store(in: &subscriptions)
}.store(in: subscriptions)

for i in 0..<3 {
wait(for: [watchEx1.wrappedValue, watchEx2.wrappedValue], timeout: 60.0)
Expand Down Expand Up @@ -187,7 +197,7 @@ class CombineSyncTests: SwiftSyncTestCase {
if objectId == objectIds[0] {
watchEx1.wrappedValue.fulfill()
}
}.store(in: &subscriptions)
}.store(in: subscriptions)

collection.watch(matchFilter: ["fullDocument._id": AnyBSON.objectId(objectIds[1])])
.onOpen {
Expand All @@ -205,7 +215,7 @@ class CombineSyncTests: SwiftSyncTestCase {
if objectId == objectIds[1] {
watchEx2.wrappedValue.fulfill()
}
}.store(in: &subscriptions)
}.store(in: subscriptions)

for i in 0..<3 {
wait(for: [watchEx1.wrappedValue, watchEx2.wrappedValue], timeout: 60.0)
Expand Down Expand Up @@ -243,7 +253,7 @@ class CombineSyncTests: SwiftSyncTestCase {
if triggered == 2 {
appEx.fulfill()
}
}.store(in: &subscriptions)
}.store(in: subscriptions)

app.emailPasswordAuth.registerUser(email: email, password: password)
.flatMap { @Sendable in self.app.login(credentials: .emailPassword(email: email, password: password)) }
Expand All @@ -256,11 +266,11 @@ class CombineSyncTests: SwiftSyncTestCase {
user.objectWillChange.sink { @Sendable user in
XCTAssert(!user.isLoggedIn)
loginEx.fulfill()
}.store(in: &self.subscriptions)
}.store(in: self.subscriptions)
XCTAssertEqual(user.id, self.app.currentUser?.id)
user.logOut { _ in } // logout user and make sure it is observed
})
.store(in: &subscriptions)
.store(in: subscriptions)
wait(for: [loginEx, appEx], timeout: 30.0)
XCTAssertEqual(self.app.allUsers.count, 1)
XCTAssertEqual(triggered, 2)
Expand Down Expand Up @@ -306,7 +316,7 @@ class CombineSyncTests: SwiftSyncTestCase {
}
.expectValue(self, chainEx) { realm in
XCTAssertEqual(realm.objects(SwiftHugeSyncObject.self).count, 2)
}.store(in: &subscriptions)
}.store(in: subscriptions)
wait(for: [chainEx, progressEx], timeout: 30.0)
}

Expand Down Expand Up @@ -334,7 +344,7 @@ class CombineSyncTests: SwiftSyncTestCase {
if triggered == 2 {
appEx.fulfill()
}
}.store(in: &subscriptions)
}.store(in: subscriptions)

app.emailPasswordAuth.registerUser(email: email, password: password)
.flatMap { @Sendable in self.app.login(credentials: .emailPassword(email: email, password: password)) }
Expand Down Expand Up @@ -639,10 +649,12 @@ class CombineFlexibleSyncTests: SwiftSyncTestCase {
try createFlexibleSyncApp()
}

var cancellables: Set<AnyCancellable> = []
nonisolated let cancellables = Locked(Set<AnyCancellable>())
override func tearDown() {
cancellables.forEach { $0.cancel() }
cancellables = []
cancellables.withLock {
$0.forEach { $0.cancel() }
$0 = []
}
super.tearDown()
}

Expand All @@ -669,7 +681,7 @@ class CombineFlexibleSyncTests: SwiftSyncTestCase {
})
}.sink(receiveCompletion: { @Sendable _ in },
receiveValue: { @Sendable _ in ex.fulfill() }
).store(in: &cancellables)
).store(in: cancellables)

waitForExpectations(timeout: 20.0, handler: nil)

Expand Down Expand Up @@ -701,7 +713,7 @@ class CombineFlexibleSyncTests: SwiftSyncTestCase {
}
ex.fulfill()
}, receiveValue: { _ in })
.store(in: &cancellables)
.store(in: cancellables)

waitForExpectations(timeout: 20.0, handler: nil)

Expand Down
Loading

0 comments on commit db56980

Please sign in to comment.