Use the SDK's offline detection everywhere (except for restarting the sync loop). (#4472)

* Use the SDK's offline state to drive the offline indicator.

* Only use network reachability for restarting the sync loop, use the homeserver reachability for requests.

* Add a separate indicator to distinguish when the server is unreachable but the device is online.
This commit is contained in:
Doug
2025-09-08 13:18:02 +01:00
committed by GitHub
parent 20b57d0ad7
commit 90504d89c8
26 changed files with 152 additions and 127 deletions
@@ -15,18 +15,17 @@ import XCTest
final class MediaProviderTests: XCTestCase {
private var mediaLoader: MediaLoaderMock!
private var imageCache: MockImageCache!
private var networkMonitor: NetworkMonitorMock!
private var reachabilitySubject = CurrentValueSubject<NetworkMonitorReachability, Never>(.reachable)
var mediaProvider: MediaProvider!
override func setUp() {
mediaLoader = MediaLoaderMock()
imageCache = MockImageCache(name: "Test")
networkMonitor = NetworkMonitorMock()
mediaProvider = MediaProvider(mediaLoader: mediaLoader,
imageCache: imageCache,
networkMonitor: networkMonitor)
homeserverReachabilityPublisher: reachabilitySubject.asCurrentValuePublisher())
}
func testLoadingRetriedOnReconnection() async throws {
@@ -38,20 +37,18 @@ final class MediaProviderTests: XCTestCase {
let loadTask = try mediaProvider.loadImageRetryingOnReconnection(MediaSourceProxy(url: .mockMXCImage, mimeType: "image/jpeg"))
let connectivitySubject = CurrentValueSubject<NetworkMonitorReachability, Never>(.unreachable)
reachabilitySubject.send(.unreachable)
mediaLoader.loadMediaContentForSourceClosure = { _ in
switch connectivitySubject.value {
mediaLoader.loadMediaContentForSourceClosure = { [reachabilitySubject] _ in
switch reachabilitySubject.value {
case .unreachable:
connectivitySubject.send(.reachable)
reachabilitySubject.send(.reachable)
throw MediaProviderTestsError.error
case .reachable:
return pngData
}
}
networkMonitor.underlyingReachabilityPublisher = connectivitySubject.asCurrentValuePublisher()
let result = try? await loadTask.value
XCTAssertNotNil(result)
@@ -61,12 +58,10 @@ final class MediaProviderTests: XCTestCase {
func testLoadingRetriedOnReconnectionCancelsAfterSecondFailure() async throws {
let loadTask = try mediaProvider.loadImageRetryingOnReconnection(MediaSourceProxy(url: .mockMXCImage, mimeType: "image/jpeg"))
let connectivitySubject = CurrentValueSubject<NetworkMonitorReachability, Never>(.reachable)
reachabilitySubject.send(.reachable)
mediaLoader.loadMediaContentForSourceThrowableError = MediaProviderTestsError.error
networkMonitor.underlyingReachabilityPublisher = connectivitySubject.asCurrentValuePublisher()
let result = try? await loadTask.value
XCTAssertNil(result)