-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Listen sequence numbers #675
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -396,20 +396,25 @@ - (void)testRoundTripSpecialFieldNames { | |
|
||
- (void)testEncodesListenRequestLabels { | ||
FSTQuery *query = FSTTestQuery(@"collection/key"); | ||
FSTQueryData *queryData = | ||
[[FSTQueryData alloc] initWithQuery:query targetID:2 purpose:FSTQueryPurposeListen]; | ||
FSTQueryData *queryData = [[FSTQueryData alloc] initWithQuery:query | ||
targetID:2 | ||
listenSequenceNumber:2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making this a different value than the targetID would help catch cases where we propagate the wrong property via the serializer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
purpose:FSTQueryPurposeListen]; | ||
|
||
NSDictionary<NSString *, NSString *> *result = | ||
[self.serializer encodedListenRequestLabelsForQueryData:queryData]; | ||
XCTAssertNil(result); | ||
|
||
queryData = | ||
[[FSTQueryData alloc] initWithQuery:query targetID:2 purpose:FSTQueryPurposeLimboResolution]; | ||
queryData = [[FSTQueryData alloc] initWithQuery:query | ||
targetID:2 | ||
listenSequenceNumber:2 | ||
purpose:FSTQueryPurposeLimboResolution]; | ||
result = [self.serializer encodedListenRequestLabelsForQueryData:queryData]; | ||
XCTAssertEqualObjects(result, @{@"goog-listen-tags" : @"limbo-document"}); | ||
|
||
queryData = [[FSTQueryData alloc] initWithQuery:query | ||
targetID:2 | ||
listenSequenceNumber:2 | ||
purpose:FSTQueryPurposeExistenceFilterMismatch]; | ||
result = [self.serializer encodedListenRequestLabelsForQueryData:queryData]; | ||
XCTAssertEqualObjects(result, @{@"goog-listen-tags" : @"existence-filter-mismatch"}); | ||
|
@@ -627,6 +632,7 @@ - (void)testEncodesResumeTokens { | |
FSTQuery *q = FSTTestQuery(@"docs"); | ||
FSTQueryData *model = [[FSTQueryData alloc] initWithQuery:q | ||
targetID:1 | ||
listenSequenceNumber:0 | ||
purpose:FSTQueryPurposeListen | ||
snapshotVersion:[FSTSnapshotVersion noVersion] | ||
resumeToken:FSTTestData(1, 2, 3, -1)]; | ||
|
@@ -647,6 +653,7 @@ - (void)testEncodesResumeTokens { | |
- (FSTQueryData *)queryDataForQuery:(FSTQuery *)query { | ||
return [[FSTQueryData alloc] initWithQuery:query | ||
targetID:1 | ||
listenSequenceNumber:0 | ||
purpose:FSTQueryPurposeListen | ||
snapshotVersion:[FSTSnapshotVersion noVersion] | ||
resumeToken:[NSData data]]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2017 Google | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's 2018 :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you say so. |
||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import "FSTTypes.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
/** | ||
* FSTListenSequence is a monotonic sequence. It is initialized with a minimum value to | ||
* exceed. All subsequent calls to next will return increasing values. | ||
*/ | ||
@interface FSTListenSequence : NSObject | ||
|
||
- (instancetype)initStartingAfter:(FSTListenSequenceNumber)after NS_DESIGNATED_INITIALIZER; | ||
|
||
- (id)init __attribute__((unavailable("Use initStartingAfter:"))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
- (FSTListenSequenceNumber)next; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#import "FSTListenSequence.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
#pragma mark - FSTListenSequence | ||
|
||
@interface FSTListenSequence () { | ||
FSTListenSequenceNumber _previousSequenceNumber; | ||
} | ||
|
||
@end | ||
|
||
@implementation FSTListenSequence | ||
|
||
#pragma mark - Constructors | ||
|
||
- (instancetype)initStartingAfter:(FSTListenSequenceNumber)after { | ||
self = [super init]; | ||
if (self) { | ||
_previousSequenceNumber = after; | ||
} | ||
return self; | ||
} | ||
|
||
#pragma mark - Public methods | ||
|
||
- (FSTListenSequenceNumber)next { | ||
_previousSequenceNumber++; | ||
return _previousSequenceNumber; | ||
} | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like most of these tests don't care about the targetID, the listenSequenceNumber, or the version. Could you add a queryDataWithQuery: overload that defaults the targetID, listenSequenceNumber, and version for tests that don't care to cut down on the noise in here?
Alternatively, since it seems like the listenSequenceNumber-testing methods don't actually use this helper maybe we can have queryDataWithQuery just default the listen sequence number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a helper that just takes a query, and transitioned most of the helper calls over to it.