diff options
author | Michael Lehenbauer <mikelehen@gmail.com> | 2018-03-05 09:49:41 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-05 09:49:41 -0800 |
commit | 34ebf10b0acc65f1924d723e82085d4104bc281d (patch) | |
tree | 98237b8eef85abdc7d464ef221a37d3bb6937be7 /Firestore/Source/Util | |
parent | 1c40e7aada6b32bbc621f06fb5f380149606a58d (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/Util')
-rw-r--r-- | Firestore/Source/Util/FSTDispatchQueue.h | 26 | ||||
-rw-r--r-- | Firestore/Source/Util/FSTDispatchQueue.mm | 4 |
2 files changed, 27 insertions, 3 deletions
diff --git a/Firestore/Source/Util/FSTDispatchQueue.h b/Firestore/Source/Util/FSTDispatchQueue.h index 9b28c9c..7922600 100644 --- a/Firestore/Source/Util/FSTDispatchQueue.h +++ b/Firestore/Source/Util/FSTDispatchQueue.h @@ -23,11 +23,24 @@ NS_ASSUME_NONNULL_BEGIN * can then be used from tests to check for the presence of callbacks or to run them early. */ typedef NS_ENUM(NSInteger, FSTTimerID) { - FSTTimerIDAll, // Sentinel value to be used with runDelayedCallbacksUntil: to run all blocks. + /** All can be used with runDelayedCallbacksUntil: to run all timers. */ + FSTTimerIDAll, + + /** + * The following 4 timers are used in FSTStream for the listen and write streams. The "Idle" timer + * is used to close the stream due to inactivity. The "ConnectionBackoff" timer is used to + * restart a stream once the appropriate backoff delay has elapsed. + */ FSTTimerIDListenStreamIdle, - FSTTimerIDListenStreamConnection, + FSTTimerIDListenStreamConnectionBackoff, FSTTimerIDWriteStreamIdle, - FSTTimerIDWriteStreamConnection + FSTTimerIDWriteStreamConnectionBackoff, + + /** + * A timer used in FSTOnlineStateTracker to transition from FSTOnlineState Unknown to Offline + * after a set timeout, rather than waiting indefinitely for success or failure. + */ + FSTTimerIDOnlineStateTimeout }; /** @@ -81,6 +94,13 @@ typedef NS_ENUM(NSInteger, FSTTimerID) { - (void)dispatchAsyncAllowingSameQueue:(void (^)(void))block; /** + * Wrapper for dispatch_sync(). Mostly meant for use in tests. + * + * @param block The block to run. + */ +- (void)dispatchSync:(void (^)(void))block; + +/** * Schedules a callback after the specified delay. * * Unlike dispatchAsync: this method does not require you to dispatch to a different queue than diff --git a/Firestore/Source/Util/FSTDispatchQueue.mm b/Firestore/Source/Util/FSTDispatchQueue.mm index 5bd7f27..3184d29 100644 --- a/Firestore/Source/Util/FSTDispatchQueue.mm +++ b/Firestore/Source/Util/FSTDispatchQueue.mm @@ -187,6 +187,10 @@ NS_ASSUME_NONNULL_BEGIN dispatch_async(self.queue, block); } +- (void)dispatchSync:(void (^)(void))block { + dispatch_sync(self.queue, block); +} + - (FSTDelayedCallback *)dispatchAfterDelay:(NSTimeInterval)delay timerID:(FSTTimerID)timerID block:(void (^)(void))block { |