diff options
author | Michael Lehenbauer <mikelehen@gmail.com> | 2017-12-15 14:56:03 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-15 14:56:03 -0800 |
commit | d4de7a6e86476991e2363dd09f623b2f0edfbee4 (patch) | |
tree | 182dfb0a5143b9465f9f01d7424982da8d0a775d /Firestore/Example/Tests/SpecTests | |
parent | 98e08bc0b883d24cf2a0e658924ddd14dbf07d65 (diff) |
b/68276665: Raise isFromCache=true events when offline (#567)
* Plumbs FSTOnlineState changes through to views.
* View sets this.current to false on FSTOnlineStateFailed, triggering
isFromCache=true events. It will automatically be returned to true
once the listen is reestablished and we get a new CURRENT message.
* Updated tests (and added one new one) to verify behavior.
* Unifies setOnlineStateToUnknown, setOnlineStateToHealthy, and
updateAndBroadcastOnlineState into a single updateOnlineState
method.
* Split disableNetwork into (public) disableNetwork and
(private) disableNetworkWithTargetOnlineState methods..
* Some miscellaneous comment cleanup.
* Add missing comment per CR feedback.
Diffstat (limited to 'Firestore/Example/Tests/SpecTests')
5 files changed, 187 insertions, 4 deletions
diff --git a/Firestore/Example/Tests/SpecTests/FSTSpecTests.m b/Firestore/Example/Tests/SpecTests/FSTSpecTests.m index 2c1b8db..0bd7b43 100644 --- a/Firestore/Example/Tests/SpecTests/FSTSpecTests.m +++ b/Firestore/Example/Tests/SpecTests/FSTSpecTests.m @@ -156,7 +156,7 @@ static NSString *const kNoIOSTag = @"no-ios"; FSTTargetID actualID = [self.driver addUserListenerWithQuery:query]; FSTTargetID expectedID = [listenSpec[0] intValue]; - XCTAssertEqual(actualID, expectedID); + XCTAssertEqual(actualID, expectedID, @"targetID assigned to listen"); } - (void)doUnlisten:(NSArray *)unlistenSpec { diff --git a/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h b/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h index 3d031bd..7cb2726 100644 --- a/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h +++ b/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h @@ -14,6 +14,7 @@ * limitations under the License. */ +#import <Firestore/Source/Remote/FSTRemoteStore.h> #import <Foundation/Foundation.h> #import "Firestore/Source/Core/FSTTypes.h" @@ -76,7 +77,7 @@ typedef NSDictionary<FSTUser *, NSArray<FSTOutstandingWrite *> *> FSTOutstanding * * Each method on the driver injects a different event into the system. */ -@interface FSTSyncEngineTestDriver : NSObject +@interface FSTSyncEngineTestDriver : NSObject <FSTOnlineStateDelegate> /** * Initializes the underlying FSTSyncEngine with the given local persistence implementation and diff --git a/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.m b/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.m index 896a292..d618aee 100644 --- a/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.m +++ b/Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.m @@ -119,7 +119,7 @@ NS_ASSUME_NONNULL_BEGIN _remoteStore.syncEngine = _syncEngine; _eventManager = [FSTEventManager eventManagerWithSyncEngine:_syncEngine]; - _remoteStore.onlineStateDelegate = _eventManager; + _remoteStore.onlineStateDelegate = self; // Set up internal event tracking for the spec tests. NSMutableArray<FSTQueryEvent *> *events = [NSMutableArray array]; @@ -139,6 +139,11 @@ NS_ASSUME_NONNULL_BEGIN return self; } +- (void)watchStreamDidChangeOnlineState:(FSTOnlineState)onlineState { + [self.syncEngine applyOnlineStateChange:onlineState]; + [self.eventManager watchStreamDidChangeOnlineState:onlineState]; +} + - (void)start { [self.localStore start]; [self.remoteStore start]; diff --git a/Firestore/Example/Tests/SpecTests/json/listen_spec_test.json b/Firestore/Example/Tests/SpecTests/json/listen_spec_test.json index e607710..7bfe557 100644 --- a/Firestore/Example/Tests/SpecTests/json/listen_spec_test.json +++ b/Firestore/Example/Tests/SpecTests/json/listen_spec_test.json @@ -1608,7 +1608,19 @@ "stateExpect": { "activeTargets": {}, "limboDocs": [] - } + }, + "expect": [ + { + "query": { + "path": "collection", + "filters": [], + "orderBys": [] + }, + "errorCode": 0, + "fromCache": true, + "hasPendingWrites": false + } + ] }, { "enableNetwork": true, diff --git a/Firestore/Example/Tests/SpecTests/json/offline_spec_test.json b/Firestore/Example/Tests/SpecTests/json/offline_spec_test.json index f542a6e..3981cec 100644 --- a/Firestore/Example/Tests/SpecTests/json/offline_spec_test.json +++ b/Firestore/Example/Tests/SpecTests/json/offline_spec_test.json @@ -294,5 +294,170 @@ ] } ] + }, + "Queries revert to fromCache=true when offline.": { + "describeName": "Offline:", + "itName": "Queries revert to fromCache=true when offline.", + "tags": [], + "config": { + "useGarbageCollection": true + }, + "steps": [ + { + "userListen": [ + 2, + { + "path": "collection", + "filters": [], + "orderBys": [] + } + ], + "stateExpect": { + "activeTargets": { + "2": { + "query": { + "path": "collection", + "filters": [], + "orderBys": [] + }, + "resumeToken": "" + } + } + } + }, + { + "watchAck": [ + 2 + ] + }, + { + "watchEntity": { + "docs": [ + [ + "collection/a", + 1000, + { + "key": "a" + } + ] + ], + "targets": [ + 2 + ] + } + }, + { + "watchCurrent": [ + [ + 2 + ], + "resume-token-1000" + ], + "watchSnapshot": 1000, + "expect": [ + { + "query": { + "path": "collection", + "filters": [], + "orderBys": [] + }, + "added": [ + [ + "collection/a", + 1000, + { + "key": "a" + } + ] + ], + "errorCode": 0, + "fromCache": false, + "hasPendingWrites": false + } + ] + }, + { + "watchStreamClose": { + "error": { + "code": 14, + "message": "Simulated Backend Error" + } + }, + "stateExpect": { + "activeTargets": { + "2": { + "query": { + "path": "collection", + "filters": [], + "orderBys": [] + }, + "resumeToken": "resume-token-1000" + } + } + } + }, + { + "watchStreamClose": { + "error": { + "code": 14, + "message": "Simulated Backend Error" + } + } + }, + { + "watchStreamClose": { + "error": { + "code": 14, + "message": "Simulated Backend Error" + } + }, + "expect": [ + { + "query": { + "path": "collection", + "filters": [], + "orderBys": [] + }, + "errorCode": 0, + "fromCache": true, + "hasPendingWrites": false + } + ] + }, + { + "watchAck": [ + 2 + ] + }, + { + "watchEntity": { + "docs": [], + "targets": [ + 2 + ] + } + }, + { + "watchCurrent": [ + [ + 2 + ], + "resume-token-1000" + ], + "watchSnapshot": 1000, + "expect": [ + { + "query": { + "path": "collection", + "filters": [], + "orderBys": [] + }, + "errorCode": 0, + "fromCache": false, + "hasPendingWrites": false + } + ] + } + ] } } |