Skip to content

Commit 076bc7b

Browse files
jullianmgithub-actions[bot]
authored andcommitted
fix: messages not being sent, waiting forever for decryption to finish - WPB-17866 (#3066)
1 parent 16002c4 commit 076bc7b

File tree

6 files changed

+81
-1
lines changed

6 files changed

+81
-1
lines changed

WireDomain/Sources/WireDomain/Synchronization/Protocols/PullPendingUpdateEventsSyncProtocol.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public protocol PullPendingUpdateEventsSyncProtocol {
2727
/// Pull pending update events from the remote, decrypt (if needed),
2828
/// and store them locally.
2929

30+
@discardableResult
3031
func pull() async throws -> AsyncStream<[UpdateEvent]>
3132

3233
}

WireDomain/Sources/WireDomain/Synchronization/SyncState.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ public enum SyncState: Equatable {
3636

3737
case liveSyncing
3838

39+
/// Sync was suspended
40+
41+
case suspended
42+
3943
public enum InitialSyncState: Equatable {
4044

4145
case pullLastEventID

WireDomain/Sources/WireDomainSupport/Sourcery/generated/AutoMockable.generated.swift

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wire-ios-sync-engine/Source/Synchronization/IncrementalSyncObserver.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ final class IncrementalSyncObserver: IncrementalSyncObserverProtocol {
5757
switch syncState {
5858
case .incrementalSyncing(.pullPendingEvents):
5959
self?.decryptionState = .inProgress
60-
case .incrementalSyncing(.processPendingEvents), .liveSyncing:
60+
case .incrementalSyncing(.processPendingEvents),
61+
.suspended,
62+
.liveSyncing:
6163
self?.decryptionState = .done
6264
default:
6365
self?.decryptionState = .notStarted

wire-ios-sync-engine/Source/Synchronization/SyncAgent.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ final class SyncAgent: NSObject, SyncAgentProtocol {
132132
WireLogger.sync.debug("suspending sync")
133133
await incrementalSyncToken?.suspend()
134134
incrementalSyncToken = nil
135+
syncStateSubject.send(.suspended)
135136
}
136137

137138
/// Performs the appropriate sync depending in the local state.
@@ -210,6 +211,7 @@ final class SyncAgent: NSObject, SyncAgentProtocol {
210211
}
211212
} catch {
212213
WireLogger.sync.error("failed to perform new incremental sync: \(String(describing: error))")
214+
syncStateSubject.send(.suspended)
213215
throw error
214216
}
215217
} else {

wire-ios-sync-engine/Tests/Source/Synchronization/SyncAgentTests.swift

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,74 @@ final class SyncAgentTests: XCTestCase, InitialSyncProvider, IncrementalSyncProv
208208
XCTAssertEqual(incrementalSync.perform_Invocations.count, 1)
209209
}
210210

211+
func testPerformIncrementalSync_Sync_State_Update_To_Suspended_When_Throwing_Error() async throws {
212+
// Given
213+
journal[.isSyncV2Enabled] = true
214+
let expectation = XCTestExpectation()
215+
216+
enum Failure: Error {
217+
case failed
218+
}
219+
220+
// Mock
221+
incrementalSync.perform_MockMethod = {
222+
throw Failure.failed
223+
}
224+
225+
var cancellable: AnyCancellable?
226+
227+
cancellable = syncStateSubject
228+
.dropFirst()
229+
.sink { state in
230+
switch state {
231+
case .suspended:
232+
// Then
233+
expectation.fulfill()
234+
default:
235+
XCTFail("Sync should be suspended when an error is thrown")
236+
}
237+
}
238+
239+
do {
240+
// When
241+
try await sut.performIncrementalSync()
242+
} catch {}
243+
244+
await fulfillment(of: [expectation])
245+
}
246+
247+
func testPerformIncrementalSync_Sync_State_Update_To_Suspended() async throws {
248+
// Given
249+
journal[.isSyncV2Enabled] = true
250+
let expectation = XCTestExpectation()
251+
252+
enum Failure: Error {
253+
case failed
254+
}
255+
256+
// Mock
257+
incrementalSync.perform_MockMethod = {
258+
throw Failure.failed
259+
}
260+
261+
var cancellable: AnyCancellable?
262+
263+
cancellable = syncStateSubject
264+
.dropFirst()
265+
.sink { state in
266+
switch state {
267+
case .suspended:
268+
// Then
269+
expectation.fulfill()
270+
default:
271+
XCTFail("Sync should be suspended")
272+
}
273+
}
274+
275+
// When
276+
sut.suspend()
277+
278+
await fulfillment(of: [expectation])
279+
}
280+
211281
}

0 commit comments

Comments
 (0)