Skip to content

Commit 87932ca

Browse files
Verifying the write handshake in FSTStreamTest
1 parent 7280673 commit 87932ca

File tree

13 files changed

+244
-710
lines changed

13 files changed

+244
-710
lines changed

Firestore/Example/Firestore.xcodeproj/project.pbxproj

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@
5959
AFE6114F0D4DAECBA7B7C089 /* Pods_Firestore_IntegrationTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B2FA635DF5D116A67A7441CD /* Pods_Firestore_IntegrationTests.framework */; };
6060
C4E749275AD0FBDF9F4716A8 /* Pods_SwiftBuildTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 32AD40BF6B0E849B07FFD05E /* Pods_SwiftBuildTest.framework */; };
6161
D5B2532E4676014F57A7EAB9 /* FSTStreamTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D5B25C0D4AADFCA3ADB883E4 /* FSTStreamTests.m */; };
62-
D5B25B66FE2390963E000FDE /* FIRTestDispatchQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = D5B25F48D1536205E8E67F2A /* FIRTestDispatchQueue.m */; };
63-
D5B25EF6FF29F02249573A35 /* FIRTestDispatchQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = D5B25F48D1536205E8E67F2A /* FIRTestDispatchQueue.m */; };
6462
DE03B2C91F2149D600A30B9C /* FSTTransactionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DE51B1C61F0D48AC0013853F /* FSTTransactionTests.m */; };
6563
DE03B2D41F2149D600A30B9C /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F5AF195388D20070C39A /* XCTest.framework */; };
6664
DE03B2D51F2149D600A30B9C /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F591195388D20070C39A /* UIKit.framework */; };
@@ -225,8 +223,6 @@
225223
CE00BABB5A3AAB44A4C209E2 /* Pods-Firestore_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_Tests/Pods-Firestore_Tests.debug.xcconfig"; sourceTree = "<group>"; };
226224
D3CC3DC5338DCAF43A211155 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
227225
D5B25C0D4AADFCA3ADB883E4 /* FSTStreamTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FSTStreamTests.m; sourceTree = "<group>"; };
228-
D5B25C8BBBB84E96C06ED244 /* FIRTestDispatchQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FIRTestDispatchQueue.h; sourceTree = "<group>"; };
229-
D5B25F48D1536205E8E67F2A /* FIRTestDispatchQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FIRTestDispatchQueue.m; sourceTree = "<group>"; };
230226
DB17FEDFB80770611A935A60 /* Pods-Firestore_IntegrationTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Firestore_IntegrationTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-Firestore_IntegrationTests/Pods-Firestore_IntegrationTests.release.xcconfig"; sourceTree = "<group>"; };
231227
DE03B2E91F2149D600A30B9C /* Firestore_IntegrationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Firestore_IntegrationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
232228
DE03B3621F215E1600A30B9C /* CAcert.pem */ = {isa = PBXFileReference; lastKnownFileType = text; path = CAcert.pem; sourceTree = "<group>"; };
@@ -565,8 +561,6 @@
565561
DE51B18A1F0D48AC0013853F /* FSTUtilTests.m */,
566562
54E9282A1F339CAD00C1953E /* XCTestCase+Await.h */,
567563
54E9282B1F339CAD00C1953E /* XCTestCase+Await.m */,
568-
D5B25F48D1536205E8E67F2A /* FIRTestDispatchQueue.m */,
569-
D5B25C8BBBB84E96C06ED244 /* FIRTestDispatchQueue.h */,
570564
);
571565
path = Util;
572566
sourceTree = "<group>";
@@ -1181,7 +1175,6 @@
11811175
DE51B1CD1F0D48CD0013853F /* FSTDatabaseInfoTests.m in Sources */,
11821176
DE51B1F21F0D49140013853F /* FSTPathTests.m in Sources */,
11831177
DE51B1DD1F0D490D0013853F /* FSTLocalStoreTests.m in Sources */,
1184-
D5B25B66FE2390963E000FDE /* FIRTestDispatchQueue.m in Sources */,
11851178
);
11861179
runOnlyForDeploymentPostprocessing = 0;
11871180
};
@@ -1206,7 +1199,6 @@
12061199
DE03B2C91F2149D600A30B9C /* FSTTransactionTests.m in Sources */,
12071200
54DA12B11F315F3800DD57A1 /* FIRValidationTests.m in Sources */,
12081201
D5B2532E4676014F57A7EAB9 /* FSTStreamTests.m in Sources */,
1209-
D5B25EF6FF29F02249573A35 /* FIRTestDispatchQueue.m in Sources */,
12101202
);
12111203
runOnlyForDeploymentPostprocessing = 0;
12121204
};

Firestore/Example/Tests/Integration/API/FIRDatabaseTests.m

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -845,22 +845,4 @@ - (void)testCantGetDocumentsWhileOffline {
845845
[self awaitExpectations];
846846
}
847847

848-
- (void)testWriteStreamReconnectsAfterIdle {
849-
FIRDocumentReference *doc = [self documentRef];
850-
FIRFirestore *firestore = doc.firestore;
851-
852-
[self writeDocumentRef:doc data:@{@"foo" : @"bar"}];
853-
[self waitForIdle:firestore];
854-
[self writeDocumentRef:doc data:@{@"foo" : @"bar"}];
855-
}
856-
857-
- (void)testWatchStreamReconnectsAfterIdle {
858-
FIRDocumentReference *doc = [self documentRef];
859-
FIRFirestore *firestore = doc.firestore;
860-
861-
[self readSnapshotForRef:[self documentRef] online:YES];
862-
[self waitForIdle:firestore];
863-
[self readSnapshotForRef:[self documentRef] online:YES];
864-
}
865-
866848
@end

Firestore/Example/Tests/Integration/FSTStreamTests.m

Lines changed: 32 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121

2222
#import "Auth/FSTEmptyCredentialsProvider.h"
2323
#import "Core/FSTDatabaseInfo.h"
24-
#import "FIRTestDispatchQueue.h"
2524
#import "FSTHelpers.h"
2625
#import "FSTIntegrationTestCase.h"
2726
#import "Model/FSTDatabaseID.h"
2827
#import "Remote/FSTDatastore.h"
2928
#import "Util/FSTAssert.h"
29+
#import "Util/FSTDispatchQueue.h"
3030

3131
/** Exposes otherwise private methods for testing. */
3232
@interface FSTStream (Testing)
@@ -44,59 +44,59 @@ @interface FSTStreamStatusDelegate : NSObject <FSTWatchStreamDelegate, FSTWriteS
4444
@property(nonatomic, weak) XCTestExpectation *expectation;
4545
@property(nonatomic, weak, readonly) FSTStream *stream;
4646

47-
- (instancetype)initWithStream:(FSTStream *)stream NS_DESIGNATED_INITIALIZER;
48-
- (instancetype)init NS_UNAVAILABLE;
4947
@end
5048

5149
@implementation FSTStreamStatusDelegate
5250

53-
- (instancetype)initWithStream:(FSTStream *)stream {
51+
- (instancetype)init {
5452
if (self = [super init]) {
5553
_states = [NSMutableArray new];
56-
_stream = stream;
5754
}
5855

5956
return self;
6057
}
6158

62-
- (void)streamDidReceiveChange:(FSTWatchChange *)change
63-
snapshotVersion:(FSTSnapshotVersion *)snapshotVersion {
64-
[_states addObject:@"didReceiveChange"];
59+
- (void)watchStreamDidOpen {
60+
[_states addObject:@"didOpen"];
6561
[_expectation fulfill];
6662
_expectation = nil;
6763
}
6864

69-
- (void)streamDidOpen {
65+
- (void)writeStreamDidOpen {
7066
[_states addObject:@"didOpen"];
7167
[_expectation fulfill];
7268
_expectation = nil;
7369
}
7470

75-
- (void)streamDidClose:(NSError *_Nullable)error {
76-
[_states addObject:@"didClose"];
71+
- (void)writeStreamDidCompleteHandshake {
72+
[_states addObject:@"didCompleteHandshake"];
7773
[_expectation fulfill];
7874
_expectation = nil;
7975
}
80-
81-
- (void)streamDidCompleteHandshake {
82-
[_states addObject:@"didCompleteHandshake"];
76+
- (void)writeStreamDidClose:(NSError *_Nullable)error {
77+
[_states addObject:@"didClose"];
8378
[_expectation fulfill];
8479
_expectation = nil;
8580
}
8681

87-
- (void)streamDidReceiveResponseWithVersion:(FSTSnapshotVersion *)commitVersion
88-
mutationResults:(NSArray<FSTMutationResult *> *)results {
89-
[_states addObject:@"didReceiveResponse"];
82+
- (void)watchStreamDidClose:(NSError *_Nullable)error {
83+
[_states addObject:@"didClose"];
9084
[_expectation fulfill];
9185
_expectation = nil;
9286
}
9387

94-
- (void)writeValue:(id)value {
95-
[self.stream writeValue:value];
88+
- (void)watchStreamDidChange:(FSTWatchChange *)change
89+
snapshotVersion:(FSTSnapshotVersion *)snapshotVersion {
90+
[_states addObject:@"didReceiveChange"];
91+
[_expectation fulfill];
92+
_expectation = nil;
9693
}
9794

98-
- (void)writesFinishedWithError:(NSError *)errorOrNil {
99-
[self.stream writesFinishedWithError:errorOrNil];
95+
- (void)writeStreamDidReceiveResponseWithVersion:(FSTSnapshotVersion *)commitVersion
96+
mutationResults:(NSArray<FSTMutationResult *> *)results {
97+
[_states addObject:@"didReceiveResponse"];
98+
[_expectation fulfill];
99+
_expectation = nil;
100100
}
101101

102102
- (void)fulfillOnCallback:(XCTestExpectation *)expectation {
@@ -113,9 +113,9 @@ @interface FSTStreamTests : XCTestCase
113113
@implementation FSTStreamTests {
114114
dispatch_queue_t _testQueue;
115115
FSTDatabaseInfo *_databaseInfo;
116-
FSTTestDispatchQueue *_workerDispatchQueue;
117116
FSTEmptyCredentialsProvider *_credentials;
118117
FSTStreamStatusDelegate *_delegate;
118+
FSTDispatchQueue *_workerDispatchQueue;
119119

120120
/** Single mutation to send to the write stream. */
121121
NSArray<FSTMutation *> *_mutations;
@@ -136,7 +136,7 @@ - (void)setUp {
136136
host:settings.host
137137
sslEnabled:settings.sslEnabled];
138138
_testQueue = dispatch_queue_create("FSTStreamTestWorkerQueue", DISPATCH_QUEUE_SERIAL);
139-
_workerDispatchQueue = [[FSTTestDispatchQueue alloc] initWithQueue:_testQueue];
139+
_workerDispatchQueue = [FSTDispatchQueue queueWith:_testQueue];
140140
_credentials = [[FSTEmptyCredentialsProvider alloc] init];
141141
}
142142

@@ -149,20 +149,19 @@ - (FSTWriteStream *)setUpWriteStream {
149149
workerDispatchQueue:_workerDispatchQueue
150150
credentials:_credentials];
151151

152-
FSTWriteStream *stream = [datastore createWriteStream];
153-
_delegate = [[FSTStreamStatusDelegate alloc] initWithStream:stream];
154-
155-
return stream;
152+
_delegate = [FSTStreamStatusDelegate new];
153+
return [datastore createWriteStreamWithDelegate:_delegate];
154+
;
156155
}
157156

158157
- (FSTWatchStream *)setUpWatchStream {
159158
FSTDatastore *datastore = [[FSTDatastore alloc] initWithDatabaseInfo:_databaseInfo
160159
workerDispatchQueue:_workerDispatchQueue
161160
credentials:_credentials];
162-
FSTWatchStream *stream = [datastore createWatchStream];
163-
_delegate = [[FSTStreamStatusDelegate alloc] initWithStream:stream];
164161

165-
return stream;
162+
_delegate = [FSTStreamStatusDelegate new];
163+
return [datastore createWatchStreamWithDelegate:_delegate];
164+
;
166165
}
167166

168167
- (void)verifyDelegate:(NSArray<NSString *> *)expectedStates {
@@ -180,7 +179,7 @@ - (void)testWatchStreamStopBeforeHandshake {
180179
XCTestExpectation *openExpectation = [self expectationWithDescription:@"open"];
181180
[_delegate fulfillOnCallback:openExpectation];
182181
[_workerDispatchQueue dispatchAsync:^{
183-
[watchStream start:_delegate];
182+
[watchStream start];
184183
}];
185184
[self awaitExpectations];
186185

@@ -203,7 +202,7 @@ - (void)testWriteStreamStopBeforeHandshake {
203202
XCTestExpectation *openExpectation = [self expectationWithDescription:@"open"];
204203
[_delegate fulfillOnCallback:openExpectation];
205204
[_workerDispatchQueue dispatchAsync:^{
206-
[writeStream start:_delegate];
205+
[writeStream start];
207206
}];
208207
[self awaitExpectations];
209208

@@ -227,7 +226,7 @@ - (void)testWriteStreamStopAfterHandshake {
227226
XCTestExpectation *openExpectation = [self expectationWithDescription:@"open"];
228227
[_delegate fulfillOnCallback:openExpectation];
229228
[_workerDispatchQueue dispatchAsync:^{
230-
[writeStream start:_delegate];
229+
[writeStream start];
231230
}];
232231
[self awaitExpectations];
233232

@@ -258,76 +257,4 @@ - (void)testWriteStreamStopAfterHandshake {
258257
[self verifyDelegate:@[ @"didOpen", @"didCompleteHandshake", @"didReceiveResponse" ]];
259258
}
260259

261-
- (void)testStreamClosesWhenIdle {
262-
FSTWriteStream *writeStream = [self setUpWriteStream];
263-
264-
XCTestExpectation *openExpectation = [self expectationWithDescription:@"open"];
265-
[_delegate fulfillOnCallback:openExpectation];
266-
[_workerDispatchQueue dispatchAsync:^{
267-
[writeStream start:_delegate];
268-
}];
269-
[self awaitExpectations];
270-
271-
XCTestExpectation *handshakeExpectation = [self expectationWithDescription:@"handshake"];
272-
[_delegate fulfillOnCallback:handshakeExpectation];
273-
[_workerDispatchQueue dispatchAsync:^{
274-
[writeStream writeHandshake];
275-
}];
276-
[self awaitExpectations];
277-
278-
XCTestExpectation *closeExpectation = [self expectationWithDescription:@"close"];
279-
[_delegate fulfillOnCallback:closeExpectation];
280-
[_workerDispatchQueue dispatchAsync:^{
281-
[writeStream markIdle];
282-
}];
283-
[self awaitExpectations];
284-
285-
dispatch_sync(_testQueue, ^{
286-
XCTAssertFalse([writeStream isOpen]);
287-
});
288-
289-
[self verifyDelegate:@[ @"didOpen", @"didCompleteHandshake", @"didClose" ]];
290-
}
291-
292-
- (void)testStreamCancelsIdleOnWrite {
293-
FSTWriteStream *writeStream = [self setUpWriteStream];
294-
295-
XCTestExpectation *openExpectation = [self expectationWithDescription:@"open"];
296-
[_delegate fulfillOnCallback:openExpectation];
297-
[_workerDispatchQueue dispatchAsync:^{
298-
[writeStream start:_delegate];
299-
}];
300-
[self awaitExpectations];
301-
302-
XCTestExpectation *handshakeExpectation = [self expectationWithDescription:@"handshake"];
303-
[_delegate fulfillOnCallback:handshakeExpectation];
304-
[_workerDispatchQueue dispatchAsync:^{
305-
[writeStream writeHandshake];
306-
}];
307-
[self awaitExpectations];
308-
309-
// Mark the stream idle, but immediately cancel the idle timer by issuing another write.
310-
XCTestExpectation *idleExpectation = [self expectationWithDescription:@"idle"];
311-
[_workerDispatchQueue fulfillOnExecution:idleExpectation];
312-
[_workerDispatchQueue dispatchAsync:^{
313-
[writeStream markIdle];
314-
}];
315-
XCTestExpectation *writeExpectation = [self expectationWithDescription:@"write"];
316-
[_delegate fulfillOnCallback:writeExpectation];
317-
[_workerDispatchQueue dispatchAsync:^{
318-
[writeStream writeMutations:_mutations];
319-
}];
320-
[self awaitExpectations];
321-
322-
dispatch_sync(_testQueue, ^{
323-
XCTAssertTrue([writeStream isOpen]);
324-
});
325-
326-
[_workerDispatchQueue dispatchAsync:^{
327-
[writeStream stop];
328-
}];
329-
330-
[self verifyDelegate:@[ @"didOpen", @"didCompleteHandshake", @"didReceiveResponse" ]];
331-
}
332-
333260
@end

0 commit comments

Comments
 (0)