@@ -16,16 +16,17 @@ class InitialSyncOrchestratorTests: XCTestCase {
16
16
17
17
override class func setUp( ) {
18
18
Amplify . Logging. logLevel = . info
19
- ModelRegistry . reset ( )
20
- PostCommentModelRegistration ( ) . registerModels ( registry: ModelRegistry . self)
21
19
}
22
20
21
+
23
22
/// - Given: An InitialSyncOrchestrator with a model dependency graph
24
23
/// - When:
25
24
/// - The orchestrator starts up
26
25
/// - Then:
27
26
/// - It performs a sync query for each registered model
28
27
func testInvokesCompletionCallback( ) throws {
28
+ ModelRegistry . reset ( )
29
+ PostCommentModelRegistration ( ) . registerModels ( registry: ModelRegistry . self)
29
30
let responder = QueryRequestListenerResponder< PaginatedList< AnyModel>> { _, listener in
30
31
let startedAt = Int ( Date ( ) . timeIntervalSince1970)
31
32
let list = PaginatedList < AnyModel > ( items: [ ] , nextToken: nil , startedAt: startedAt)
@@ -42,11 +43,10 @@ class InitialSyncOrchestratorTests: XCTestCase {
42
43
43
44
let reconciliationQueue = MockReconciliationQueue ( )
44
45
45
- let orchestrator : InitialSyncOrchestrator =
46
- AWSInitialSyncOrchestrator ( dataStoreConfiguration: . default,
47
- api: apiPlugin,
48
- reconciliationQueue: reconciliationQueue,
49
- storageAdapter: storageAdapter)
46
+ let orchestrator = AWSInitialSyncOrchestrator ( dataStoreConfiguration: . default,
47
+ api: apiPlugin,
48
+ reconciliationQueue: reconciliationQueue,
49
+ storageAdapter: storageAdapter)
50
50
51
51
let syncCallbackReceived = expectation ( description: " Sync callback received, sync operation is complete " )
52
52
let syncQueriesStartedReceived = expectation ( description: " syncQueriesStarted received " )
@@ -89,16 +89,85 @@ class InitialSyncOrchestratorTests: XCTestCase {
89
89
}
90
90
91
91
waitForExpectations ( timeout: 1 )
92
+ XCTAssertEqual ( orchestrator. syncOperationQueue. maxConcurrentOperationCount, 1 )
92
93
Amplify . Hub. removeListener ( hubListener)
93
94
sink. cancel ( )
94
95
}
95
96
97
+ /// - Given: An InitialSyncOrchestrator with a model dependency graph containing no associations
98
+ /// - When:
99
+ /// - The orchestrator starts up
100
+ /// - Then:
101
+ /// - It performs a sync query for each registered model with concurrency set to count of models
102
+ func testInvokesCompletionCallback_ModelWithNoAssociations( ) throws {
103
+ ModelRegistry . reset ( )
104
+ struct TestModelsWithNoAssociations : AmplifyModelRegistration {
105
+ func registerModels( registry: ModelRegistry . Type ) {
106
+ // Models without no associations
107
+ registry. register ( modelType: MockSynced . self)
108
+ registry. register ( modelType: ExampleWithEveryType . self)
109
+ }
110
+
111
+ let version : String = " 1 "
112
+ }
113
+ TestModelsWithNoAssociations ( ) . registerModels ( registry: ModelRegistry . self)
114
+
115
+ let responder = QueryRequestListenerResponder< PaginatedList< AnyModel>> { _, listener in
116
+ let startedAt = Int ( Date ( ) . timeIntervalSince1970)
117
+ let list = PaginatedList < AnyModel > ( items: [ ] , nextToken: nil , startedAt: startedAt)
118
+ let event : GraphQLOperation < PaginatedList < AnyModel > > . OperationResult = . success( . success( list) )
119
+ listener ? ( event)
120
+ return nil
121
+ }
122
+
123
+ let apiPlugin = MockAPICategoryPlugin ( )
124
+ apiPlugin. responders [ . queryRequestListener] = responder
125
+
126
+ let storageAdapter = MockSQLiteStorageEngineAdapter ( )
127
+ storageAdapter. returnOnQueryModelSyncMetadata ( nil )
128
+
129
+ let reconciliationQueue = MockReconciliationQueue ( )
130
+
131
+ let orchestrator = AWSInitialSyncOrchestrator ( dataStoreConfiguration: . default,
132
+ api: apiPlugin,
133
+ reconciliationQueue: reconciliationQueue,
134
+ storageAdapter: storageAdapter)
135
+ let syncCallbackReceived = expectation ( description: " Sync callback received, sync operation is complete " )
136
+ let syncStartedReceived = expectation ( description: " Sync started received, sync operation started " )
137
+ syncStartedReceived. expectedFulfillmentCount = 2
138
+ let finishedReceived = expectation ( description: " InitialSyncOperation finished paginating and offering " )
139
+ finishedReceived. expectedFulfillmentCount = 2
140
+ let sink = orchestrator
141
+ . publisher
142
+ . sink ( receiveCompletion: { _ in } ,
143
+ receiveValue: { value in
144
+ switch value {
145
+ case . started:
146
+ syncStartedReceived. fulfill ( )
147
+ case . finished:
148
+ finishedReceived. fulfill ( )
149
+ default :
150
+ break
151
+ }
152
+ } )
153
+
154
+ orchestrator. sync { _ in
155
+ syncCallbackReceived. fulfill ( )
156
+ }
157
+
158
+ waitForExpectations ( timeout: 1 )
159
+ XCTAssertEqual ( orchestrator. syncOperationQueue. maxConcurrentOperationCount, 2 )
160
+ sink. cancel ( )
161
+ }
162
+
96
163
/// - Given: An InitialSyncOrchestrator with a model dependency graph
97
164
/// - When:
98
165
/// - The orchestrator starts up
99
166
/// - Then:
100
167
/// - It queries models in dependency order, from "parent" to "child"
101
168
func testShouldQueryModelsInDependencyOrder( ) {
169
+ ModelRegistry . reset ( )
170
+ PostCommentModelRegistration ( ) . registerModels ( registry: ModelRegistry . self)
102
171
let postWasQueried = expectation ( description: " Post was queried " )
103
172
let commentWasQueried = expectation ( description: " Comment was queried " )
104
173
let responder = QueryRequestListenerResponder< PaginatedList< AnyModel>> { request, listener in
@@ -125,11 +194,10 @@ class InitialSyncOrchestratorTests: XCTestCase {
125
194
126
195
let reconciliationQueue = MockReconciliationQueue ( )
127
196
128
- let orchestrator : InitialSyncOrchestrator =
129
- AWSInitialSyncOrchestrator ( dataStoreConfiguration: . default,
130
- api: apiPlugin,
131
- reconciliationQueue: reconciliationQueue,
132
- storageAdapter: storageAdapter)
197
+ let orchestrator = AWSInitialSyncOrchestrator ( dataStoreConfiguration: . default,
198
+ api: apiPlugin,
199
+ reconciliationQueue: reconciliationQueue,
200
+ storageAdapter: storageAdapter)
133
201
134
202
let syncStartedReceived = expectation ( description: " Sync started received, sync operation started " )
135
203
syncStartedReceived. expectedFulfillmentCount = 2
@@ -152,6 +220,7 @@ class InitialSyncOrchestratorTests: XCTestCase {
152
220
orchestrator. sync { _ in }
153
221
154
222
waitForExpectations ( timeout: 1 )
223
+ XCTAssertEqual ( orchestrator. syncOperationQueue. maxConcurrentOperationCount, 1 )
155
224
sink. cancel ( )
156
225
}
157
226
@@ -162,6 +231,8 @@ class InitialSyncOrchestratorTests: XCTestCase {
162
231
/// - It queries models in dependency order, from "parent" to "child", even if parent data is returned in
163
232
/// multiple pages
164
233
func testShouldQueryModelsInDependencyOrderWithPaginatedResults( ) {
234
+ ModelRegistry . reset ( )
235
+ PostCommentModelRegistration ( ) . registerModels ( registry: ModelRegistry . self)
165
236
let pageCount = 50
166
237
167
238
let postWasQueried = expectation ( description: " Post was queried " )
@@ -196,11 +267,10 @@ class InitialSyncOrchestratorTests: XCTestCase {
196
267
197
268
let reconciliationQueue = MockReconciliationQueue ( )
198
269
199
- let orchestrator : InitialSyncOrchestrator =
200
- AWSInitialSyncOrchestrator ( dataStoreConfiguration: . default,
201
- api: apiPlugin,
202
- reconciliationQueue: reconciliationQueue,
203
- storageAdapter: storageAdapter)
270
+ let orchestrator = AWSInitialSyncOrchestrator ( dataStoreConfiguration: . default,
271
+ api: apiPlugin,
272
+ reconciliationQueue: reconciliationQueue,
273
+ storageAdapter: storageAdapter)
204
274
205
275
let syncStartedReceived = expectation ( description: " Sync started received, sync operation started " )
206
276
syncStartedReceived. expectedFulfillmentCount = 2
@@ -223,6 +293,7 @@ class InitialSyncOrchestratorTests: XCTestCase {
223
293
orchestrator. sync { _ in }
224
294
225
295
waitForExpectations ( timeout: 1 )
296
+ XCTAssertEqual ( orchestrator. syncOperationQueue. maxConcurrentOperationCount, 1 )
226
297
sink. cancel ( )
227
298
}
228
299
0 commit comments