aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Source/Core
diff options
context:
space:
mode:
authorGravatar Michael Lehenbauer <mikelehen@gmail.com>2018-03-05 09:49:41 -0800
committerGravatar GitHub <noreply@github.com>2018-03-05 09:49:41 -0800
commit34ebf10b0acc65f1924d723e82085d4104bc281d (patch)
tree98237b8eef85abdc7d464ef221a37d3bb6937be7 /Firestore/Source/Core
parent1c40e7aada6b32bbc621f06fb5f380149606a58d (diff)
Add 10 second timeout waiting for connection before client behaves as-if offline. (#872)
[Port of https://github.com/firebase/firebase-js-sdk/commit/0fa319e5e019dd0d40ab441d2ff9f8f6d4724e43] * Refactored FSTOnlineState tracking out of FSTRemoteStore and into new FSTOnlineStateTracker component. * Added a 10 second timeout to transition from OnlineState.Unknown to OnlineState.Offline rather than waiting indefinitely for the stream to succeed or fail. * Removed hack to run SpecTests using an FSTDispatchQueue that wrapped dispatch_get_main_queue(). This was incompatible with [FSTDispatchQueue runDelayedCallbacksUntil:] since it queues work and blocks waiting for it to complete. Now spec tests create / use a proper FSTDispatchQueue. * Added a SpecTest to verify OnlineState timeout behavior. * Misc cleanup: * Renamed FSTOnlineState states: Failed => Offline, Healthy => Online * Renamed FSTTimerIds (ListenStreamConnection => ListenStreamConnectionBackoff) * Added ability to run timers from spec tests.
Diffstat (limited to 'Firestore/Source/Core')
-rw-r--r--Firestore/Source/Core/FSTEventManager.mm8
-rw-r--r--Firestore/Source/Core/FSTFirestoreClient.mm4
-rw-r--r--Firestore/Source/Core/FSTTypes.h19
-rw-r--r--Firestore/Source/Core/FSTView.mm2
4 files changed, 21 insertions, 12 deletions
diff --git a/Firestore/Source/Core/FSTEventManager.mm b/Firestore/Source/Core/FSTEventManager.mm
index bc204a0..b02fc5f 100644
--- a/Firestore/Source/Core/FSTEventManager.mm
+++ b/Firestore/Source/Core/FSTEventManager.mm
@@ -169,9 +169,9 @@ NS_ASSUME_NONNULL_BEGIN
return YES;
}
- // NOTE: We consider OnlineState.Unknown as online (it should become Failed
- // or Online if we wait long enough).
- BOOL maybeOnline = onlineState != FSTOnlineStateFailed;
+ // NOTE: We consider OnlineState.Unknown as online (it should become Offline or Online if we
+ // wait long enough).
+ BOOL maybeOnline = onlineState != FSTOnlineStateOffline;
// Don't raise the event if we're online, aren't synced yet (checked
// above) and are waiting for a sync.
if (self.options.waitForSyncWhenOnline && maybeOnline) {
@@ -180,7 +180,7 @@ NS_ASSUME_NONNULL_BEGIN
}
// Raise data from cache if we have any documents or we are offline
- return !snapshot.documents.isEmpty || onlineState == FSTOnlineStateFailed;
+ return !snapshot.documents.isEmpty || onlineState == FSTOnlineStateOffline;
}
- (BOOL)shouldRaiseEventForSnapshot:(FSTViewSnapshot *)snapshot {
diff --git a/Firestore/Source/Core/FSTFirestoreClient.mm b/Firestore/Source/Core/FSTFirestoreClient.mm
index fb86e0b..288cbe2 100644
--- a/Firestore/Source/Core/FSTFirestoreClient.mm
+++ b/Firestore/Source/Core/FSTFirestoreClient.mm
@@ -181,7 +181,9 @@ NS_ASSUME_NONNULL_BEGIN
workerDispatchQueue:self.workerDispatchQueue
credentials:_credentialsProvider];
- _remoteStore = [FSTRemoteStore remoteStoreWithLocalStore:_localStore datastore:datastore];
+ _remoteStore = [[FSTRemoteStore alloc] initWithLocalStore:_localStore
+ datastore:datastore
+ workerDispatchQueue:self.workerDispatchQueue];
_syncEngine = [[FSTSyncEngine alloc] initWithLocalStore:_localStore
remoteStore:_remoteStore
diff --git a/Firestore/Source/Core/FSTTypes.h b/Firestore/Source/Core/FSTTypes.h
index 877ec94..688b2bf 100644
--- a/Firestore/Source/Core/FSTTypes.h
+++ b/Firestore/Source/Core/FSTTypes.h
@@ -65,12 +65,18 @@ typedef void (^FSTVoidMaybeDocumentArrayErrorBlock)(
typedef void (^FSTTransactionBlock)(FSTTransaction *transaction,
void (^completion)(id _Nullable, NSError *_Nullable));
-/** Describes the online state of the Firestore client */
+/**
+ * Describes the online state of the Firestore client. Note that this does not indicate whether
+ * or not the remote store is trying to connect or not. This is primarily used by the View /
+ * EventManager code to change their behavior while offline (e.g. get() calls shouldn't wait for
+ * data from the server and snapshot events should set metadata.isFromCache=true).
+ */
typedef NS_ENUM(NSUInteger, FSTOnlineState) {
/**
* The Firestore client is in an unknown online state. This means the client is either not
* actively trying to establish a connection or it is currently trying to establish a connection,
- * but it has not succeeded or failed yet.
+ * but it has not succeeded or failed yet. Higher-level components should not operate in
+ * offline mode.
*/
FSTOnlineStateUnknown,
@@ -79,13 +85,14 @@ typedef NS_ENUM(NSUInteger, FSTOnlineState) {
* successful connection and there has been at least one successful message received from the
* backends.
*/
- FSTOnlineStateHealthy,
+ FSTOnlineStateOnline,
/**
- * The client considers itself offline. It is either trying to establish a connection but
- * failing, or it has been explicitly marked offline via a call to `disableNetwork`.
+ * The client is either trying to establish a connection but failing, or it has been explicitly
+ * marked offline via a call to `disableNetwork`. Higher-level components should operate in
+ * offline mode.
*/
- FSTOnlineStateFailed
+ FSTOnlineStateOffline
};
NS_ASSUME_NONNULL_END
diff --git a/Firestore/Source/Core/FSTView.mm b/Firestore/Source/Core/FSTView.mm
index d6b4558..b2a39cb 100644
--- a/Firestore/Source/Core/FSTView.mm
+++ b/Firestore/Source/Core/FSTView.mm
@@ -337,7 +337,7 @@ static NSComparisonResult FSTCompareDocumentViewChangeTypes(FSTDocumentViewChang
}
- (FSTViewChange *)applyChangedOnlineState:(FSTOnlineState)onlineState {
- if (self.isCurrent && onlineState == FSTOnlineStateFailed) {
+ if (self.isCurrent && onlineState == FSTOnlineStateOffline) {
// If we're offline, set `current` to NO and then call applyChanges to refresh our syncState
// and generate an FSTViewChange as appropriate. We are guaranteed to get a new FSTTargetChange
// that sets `current` back to YES once the client is back online.