Skip to content

Commit 8fd3db4

Browse files
authored
chore: kickoff v1 release
2 parents 982760d + 334e206 commit 8fd3db4

File tree

6 files changed

+44
-30
lines changed

6 files changed

+44
-30
lines changed

AmplifyPlugins/DataStore/AWSDataStoreCategoryPlugin/AWSDataStorePlugin.swift

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,7 @@ final public class AWSDataStorePlugin: DataStoreCategoryPlugin {
198198
case .failure(let dataStoreError):
199199
log.error("StorageEngine completed with error: \(dataStoreError)")
200200
case .finished:
201-
break
202-
}
203-
stop { result in
204-
switch result {
205-
case .success:
206-
self.log.info("Stopping DataStore successful.")
207-
return
208-
case .failure(let error):
209-
self.log.error("Failed to stop StorageEngine with error: \(error)")
210-
}
201+
log.debug("StorageEngine completed successfully")
211202
}
212203
}
213204

AmplifyPlugins/DataStore/AWSDataStoreCategoryPlugin/Storage/StorageEngine.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,18 @@ final class StorageEngine: StorageEngineBehavior {
133133
func onReceiveCompletion(receiveCompletion: Subscribers.Completion<DataStoreError>) {
134134
switch receiveCompletion {
135135
case .failure(let dataStoreError):
136-
storageEnginePublisher.send(completion: .failure(dataStoreError))
136+
log.error("RemoteSyncEngine completed with error \(dataStoreError)")
137137
case .finished:
138-
storageEnginePublisher.send(completion: .finished)
138+
log.debug("RemoteSyncEngine completed successfully")
139+
}
140+
141+
stopSync { result in
142+
switch result {
143+
case .success:
144+
self.log.info("Stopping SyncEngine successful.")
145+
case .failure(let error):
146+
self.log.error("Failed to stop SyncEngine with error: \(error)")
147+
}
139148
}
140149
}
141150

@@ -323,6 +332,7 @@ final class StorageEngine: StorageEngineBehavior {
323332
func clear(completion: @escaping DataStoreCallback<Void>) {
324333
if let syncEngine = syncEngine {
325334
syncEngine.stop(completion: { _ in
335+
self.syncEngine = nil
326336
self.storageAdapter.clear(completion: completion)
327337
})
328338
} else {

AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginIntegrationTests/DataStoreObserveQueryTests.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,11 @@ class DataStoreObserveQueryTests: SyncEngineIntegrationTestBase {
252252
snapshotWithIsSynced.fulfill()
253253
}
254254
}
255-
savePostAndWaitForSync(Post(title: "title", content: "content", createdAt: .now()))
255+
let newPost = Post(title: "title", content: "content", createdAt: .now())
256+
savePostAndWaitForSync(newPost)
256257
wait(for: [snapshotWithIsSynced], timeout: 100)
257-
XCTAssertTrue(snapshots.count >= 2)
258-
XCTAssertFalse(snapshots[0].isSynced)
258+
XCTAssertTrue(!snapshots.isEmpty)
259+
XCTAssertTrue(snapshots.last!.items.contains(newPost))
259260
XCTAssertTrue(snapshots.last!.isSynced)
260261
XCTAssertTrue(snapshots.last!.items.count > numberOfPosts)
261262
sink.cancel()

AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Core/AWSDataStorePluginTests.swift

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,8 @@ class AWSDataStorePluginTests: XCTestCase {
557557
func testStopStorageEngineOnTerminalEvent() {
558558
let storageEngine = MockStorageEngineBehavior()
559559
let stopExpectation = expectation(description: "stop should be called")
560-
var count = 0
561560
storageEngine.responders[.stopSync] = StopSyncResponder { _ in
562-
count = self.expect(stopExpectation, count, 1)
561+
stopExpectation.fulfill()
563562
}
564563
let storageEngineBehaviorFactory: StorageEngineBehaviorFactory = {_, _, _, _, _, _ throws in
565564
return storageEngine
@@ -571,25 +570,24 @@ class AWSDataStorePluginTests: XCTestCase {
571570
validAPIPluginKey: "MockAPICategoryPlugin",
572571
validAuthPluginKey: "MockAuthCategoryPlugin")
573572

574-
let semaphore = DispatchSemaphore(value: 0)
573+
let startExpectation = expectation(description: "Plugin should started")
575574
plugin.start(completion: {_ in
576575
XCTAssertNotNil(plugin.storageEngine)
577576
XCTAssertNotNil(plugin.dataStorePublisher)
578-
semaphore.signal()
577+
startExpectation.fulfill()
579578
})
580-
semaphore.wait()
579+
wait(for: [startExpectation], timeout: 1)
581580

582-
storageEngine.mockPublisher.send(completion: .finished)
581+
storageEngine.mockSyncEnginePublisher.send(completion: .finished)
583582

584-
waitForExpectations(timeout: 1.0)
583+
wait(for: [stopExpectation], timeout: 1)
585584
}
586585

587586
func testStopStorageEngineOnTerminalFailureEvent() {
588587
let storageEngine = MockStorageEngineBehavior()
589588
let stopExpectation = expectation(description: "stop should be called")
590-
var count = 0
591589
storageEngine.responders[.stopSync] = StopSyncResponder { _ in
592-
count = self.expect(stopExpectation, count, 1)
590+
stopExpectation.fulfill()
593591
}
594592
let storageEngineBehaviorFactory: StorageEngineBehaviorFactory = {_, _, _, _, _, _ throws in
595593
return storageEngine
@@ -601,16 +599,17 @@ class AWSDataStorePluginTests: XCTestCase {
601599
validAPIPluginKey: "MockAPICategoryPlugin",
602600
validAuthPluginKey: "MockAuthCategoryPlugin")
603601

604-
let semaphore = DispatchSemaphore(value: 0)
602+
let startExpectation = expectation(description: "Plugin should started")
605603
plugin.start(completion: {_ in
606604
XCTAssertNotNil(plugin.storageEngine)
607605
XCTAssertNotNil(plugin.dataStorePublisher)
608-
semaphore.signal()
606+
startExpectation.fulfill()
609607
})
610-
semaphore.wait()
611608

612-
storageEngine.mockPublisher.send(completion: .failure(.internalOperation("", "", nil)))
609+
wait(for: [startExpectation], timeout: 1)
613610

614-
waitForExpectations(timeout: 1.0)
611+
storageEngine.mockSyncEnginePublisher.send(completion: .failure(.internalOperation("", "", nil)))
612+
613+
wait(for: [stopExpectation], timeout: 1)
615614
}
616615
} // swiftlint:disable:this file_length

AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Sync/SubscriptionSync/Support/MockSQLiteStorageEngineAdapter.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,15 @@ class MockStorageEngineBehavior: StorageEngineBehavior {
303303

304304
}
305305

306+
var mockSyncEnginePublisher: PassthroughSubject<RemoteSyncEngineEvent, DataStoreError>!
307+
var mockSyncEngineSubscription: AnyCancellable! {
308+
willSet {
309+
if let subscription = mockSyncEngineSubscription {
310+
subscription.cancel()
311+
}
312+
}
313+
}
314+
306315
var mockPublisher = PassthroughSubject<StorageEngineEvent, DataStoreError>()
307316
var publisher: AnyPublisher<StorageEngineEvent, DataStoreError> {
308317
mockPublisher.eraseToAnyPublisher()
@@ -314,6 +323,10 @@ class MockStorageEngineBehavior: StorageEngineBehavior {
314323
responder.callback("")
315324
}
316325
startedSync = true
326+
mockSyncEnginePublisher = PassthroughSubject()
327+
mockSyncEngineSubscription = mockSyncEnginePublisher.sink(receiveCompletion: { completion in
328+
self.stopSync(completion: { _ in })
329+
}, receiveValue: { _ in })
317330
return .success(.successfullyInitialized)
318331
} else {
319332
return .success(.alreadyInitialized)

AmplifyPlugins/DataStore/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,4 @@ SPEC CHECKSUMS:
128128

129129
PODFILE CHECKSUM: 0bab7193bebdf470839514f327440893b0d26090
130130

131-
COCOAPODS: 1.11.3
131+
COCOAPODS: 1.12.0

0 commit comments

Comments
 (0)