@@ -19,15 +19,15 @@ class StoreSubscriptionTests: XCTestCase {
19
19
20
20
// MARK: - Tests
21
21
22
- func testSubscriberIsNotifiedOfStoreUpdate( ) throws {
22
+ func testSubscriberIsNotifiedOfStoreUpdate( ) async throws {
23
23
let cacheKeyChangeExpectation = XCTestExpectation ( description: " Subscriber is notified of cache key change " )
24
24
let expectedChangeKeySet : Set < String > = [ " QUERY_ROOT.__typename " , " QUERY_ROOT.name " ]
25
25
let subscriber = SimpleSubscriber ( cacheKeyChangeExpectation, expectedChangeKeySet)
26
26
27
27
store. subscribe ( subscriber)
28
- addTeardownBlock { self . store. unsubscribe ( subscriber) }
28
+ addTeardownBlock { [ store] in store! . unsubscribe ( subscriber) }
29
29
30
- store. publish (
30
+ try await store. publish (
31
31
records: [
32
32
" QUERY_ROOT " : [
33
33
" __typename " : " Hero " ,
@@ -36,7 +36,7 @@ class StoreSubscriptionTests: XCTestCase {
36
36
]
37
37
)
38
38
39
- wait ( for : [ cacheKeyChangeExpectation] , timeout: Self . defaultWaitTimeout)
39
+ await fulfillment ( of : [ cacheKeyChangeExpectation] , timeout: Self . defaultWaitTimeout)
40
40
}
41
41
42
42
func testUnsubscribeRemovesSubscriberFromApolloStore( ) throws {
@@ -50,7 +50,7 @@ class StoreSubscriptionTests: XCTestCase {
50
50
}
51
51
52
52
/// Fufills the provided expectation when all expected keys have been observed.
53
- internal class SimpleSubscriber : ApolloStoreSubscriber {
53
+ internal actor SimpleSubscriber : ApolloStoreSubscriber {
54
54
private let expectation : XCTestExpectation
55
55
private var changeSet : Set < String >
56
56
@@ -59,12 +59,18 @@ class StoreSubscriptionTests: XCTestCase {
59
59
self . changeSet = changeSet
60
60
}
61
61
62
- func store( _ store: ApolloStore ,
63
- didChangeKeys changedKeys: Set < CacheKey > ,
64
- contextIdentifier: UUID ? ) {
65
- changeSet. subtract ( changedKeys)
66
- if ( changeSet. isEmpty) {
67
- expectation. fulfill ( )
62
+ func isolatedDo( _ block: @escaping ( isolated SimpleSubscriber) -> Void ) {
63
+ block ( self )
64
+ }
65
+
66
+ nonisolated func store( _ store: ApolloStore , didChangeKeys changedKeys: Set < CacheKey > ) {
67
+ Task {
68
+ await self . isolatedDo {
69
+ $0. changeSet. subtract ( changedKeys)
70
+ if ( $0. changeSet. isEmpty) {
71
+ $0. expectation. fulfill ( )
72
+ }
73
+ }
68
74
}
69
75
}
70
76
}
0 commit comments