Skip to content

Commit 81ee594

Browse files
authored
DispatchQueue delayed callback improvements + testing (firebase#784)
Basically a port of firebase/firebase-js-sdk@a1e346f and firebase/firebase-js-sdk@fce4168 * Introduces a DelayedCallback helper class in FSTDispatchQueue to encapsulate delayed callback logic. * Adds cancellation support. * Updates the idle timer in FSTStream to use new cancellation support. * Adds a FSTTimerId enum for identifying delayed operations on the queue and uses it to identify our existing backoff and idle timers. * Added containsDelayedCallback: and runDelayedCallbacksUntil: methods to FSTDispatchQueue which can be used from tests to check for the presence of a callback or to schedule them to run early. * Removes FSTTestDispatchQueue and changes idle tests to use new test methods.
1 parent fd9fd27 commit 81ee594

14 files changed

+442
-170
lines changed

Firestore/Example/Firestore.xcodeproj/project.pbxproj

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,12 @@
3737
5492E03320213FFC00B64F25 /* FSTSyncEngineTestDriver.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E02E20213FFC00B64F25 /* FSTSyncEngineTestDriver.mm */; };
3838
5492E03420213FFC00B64F25 /* FSTMemorySpecTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E02F20213FFC00B64F25 /* FSTMemorySpecTests.mm */; };
3939
5492E03520213FFC00B64F25 /* FSTSpecTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E03020213FFC00B64F25 /* FSTSpecTests.mm */; };
40-
5492E03B2021401F00B64F25 /* FSTTestDispatchQueue.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0362021401E00B64F25 /* FSTTestDispatchQueue.mm */; };
4140
5492E03C2021401F00B64F25 /* XCTestCase+Await.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0372021401E00B64F25 /* XCTestCase+Await.mm */; };
4241
5492E03D2021401F00B64F25 /* FSTAssertTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0382021401E00B64F25 /* FSTAssertTests.mm */; };
4342
5492E03E2021401F00B64F25 /* FSTEventAccumulator.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0392021401F00B64F25 /* FSTEventAccumulator.mm */; };
4443
5492E03F2021401F00B64F25 /* FSTHelpers.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E03A2021401F00B64F25 /* FSTHelpers.mm */; };
4544
5492E041202143E700B64F25 /* FSTEventAccumulator.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0392021401F00B64F25 /* FSTEventAccumulator.mm */; };
4645
5492E0422021440500B64F25 /* FSTHelpers.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E03A2021401F00B64F25 /* FSTHelpers.mm */; };
47-
5492E0432021441E00B64F25 /* FSTTestDispatchQueue.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0362021401E00B64F25 /* FSTTestDispatchQueue.mm */; };
4846
5492E0442021457E00B64F25 /* XCTestCase+Await.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0372021401E00B64F25 /* XCTestCase+Await.mm */; };
4947
5492E050202154AA00B64F25 /* FIRCollectionReferenceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E045202154AA00B64F25 /* FIRCollectionReferenceTests.mm */; };
5048
5492E051202154AA00B64F25 /* FIRQueryTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E046202154AA00B64F25 /* FIRQueryTests.mm */; };
@@ -133,6 +131,7 @@
133131
6003F5BA195388D20070C39A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5B8195388D20070C39A /* InfoPlist.strings */; };
134132
6ED54761B845349D43DB6B78 /* Pods_Firestore_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 75A6FE51C1A02DF38F62FAAD /* Pods_Firestore_Example.framework */; };
135133
71719F9F1E33DC2100824A3D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 71719F9D1E33DC2100824A3D /* LaunchScreen.storyboard */; };
134+
7346E61D20325C6900FD6CEF /* FSTDispatchQueueTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7346E61C20325C6900FD6CEF /* FSTDispatchQueueTests.mm */; };
136135
873B8AEB1B1F5CCA007FD442 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */; };
137136
AB356EF7200EA5EB0089B766 /* field_value_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB356EF6200EA5EB0089B766 /* field_value_test.cc */; };
138137
AB380CFB2019388600D97691 /* target_id_generator_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB380CF82019382300D97691 /* target_id_generator_test.cc */; };
@@ -228,7 +227,6 @@
228227
5492E02E20213FFC00B64F25 /* FSTSyncEngineTestDriver.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTSyncEngineTestDriver.mm; sourceTree = "<group>"; };
229228
5492E02F20213FFC00B64F25 /* FSTMemorySpecTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTMemorySpecTests.mm; sourceTree = "<group>"; };
230229
5492E03020213FFC00B64F25 /* FSTSpecTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTSpecTests.mm; sourceTree = "<group>"; };
231-
5492E0362021401E00B64F25 /* FSTTestDispatchQueue.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTTestDispatchQueue.mm; sourceTree = "<group>"; };
232230
5492E0372021401E00B64F25 /* XCTestCase+Await.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "XCTestCase+Await.mm"; sourceTree = "<group>"; };
233231
5492E0382021401E00B64F25 /* FSTAssertTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTAssertTests.mm; sourceTree = "<group>"; };
234232
5492E0392021401F00B64F25 /* FSTEventAccumulator.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTEventAccumulator.mm; sourceTree = "<group>"; };
@@ -335,6 +333,7 @@
335333
6003F5B9195388D20070C39A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
336334
69F6A10DBD6187489481CD76 /* Pods_Firestore_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
337335
71719F9E1E33DC2100824A3D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
336+
7346E61C20325C6900FD6CEF /* FSTDispatchQueueTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTDispatchQueueTests.mm; sourceTree = "<group>"; };
338337
75A6FE51C1A02DF38F62FAAD /* Pods_Firestore_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
339338
873B8AEA1B1F5CCA007FD442 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Main.storyboard; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
340339
8E002F4AD5D9B6197C940847 /* Firestore.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = Firestore.podspec; path = ../Firestore.podspec; sourceTree = "<group>"; };
@@ -364,7 +363,6 @@
364363
B686F2B02024FFD70028D6BE /* resource_path_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = resource_path_test.cc; sourceTree = "<group>"; };
365364
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>"; };
366365
D3CC3DC5338DCAF43A211155 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
367-
D5B259DAA9149B80D6245B57 /* FSTTestDispatchQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSTTestDispatchQueue.h; sourceTree = "<group>"; };
368366
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>"; };
369367
DE03B2E91F2149D600A30B9C /* Firestore_IntegrationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Firestore_IntegrationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
370368
DE03B3621F215E1600A30B9C /* CAcert.pem */ = {isa = PBXFileReference; lastKnownFileType = text; path = CAcert.pem; sourceTree = "<group>"; };
@@ -724,10 +722,9 @@
724722
5492E03A2021401F00B64F25 /* FSTHelpers.mm */,
725723
54E9281E1F33950B00C1953E /* FSTIntegrationTestCase.h */,
726724
5491BC711FB44593008B3588 /* FSTIntegrationTestCase.mm */,
727-
D5B259DAA9149B80D6245B57 /* FSTTestDispatchQueue.h */,
728-
5492E0362021401E00B64F25 /* FSTTestDispatchQueue.mm */,
729725
54E9282A1F339CAD00C1953E /* XCTestCase+Await.h */,
730726
5492E0372021401E00B64F25 /* XCTestCase+Await.mm */,
727+
7346E61C20325C6900FD6CEF /* FSTDispatchQueueTests.mm */,
731728
);
732729
path = Util;
733730
sourceTree = "<group>";
@@ -1272,6 +1269,7 @@
12721269
isa = PBXSourcesBuildPhase;
12731270
buildActionMask = 2147483647;
12741271
files = (
1272+
7346E61D20325C6900FD6CEF /* FSTDispatchQueueTests.mm in Sources */,
12751273
DE2EF0881F3D0B6E003D0CDC /* FSTTreeSortedDictionaryTests.m in Sources */,
12761274
ABE6637A201FA81900ED349A /* database_id_test.cc in Sources */,
12771275
5492E0AF2021552D00B64F25 /* FSTReferenceSetTests.mm in Sources */,
@@ -1360,7 +1358,6 @@
13601358
5492E052202154AB00B64F25 /* FIRGeoPointTests.mm in Sources */,
13611359
5492E0C72021557E00B64F25 /* FSTSerializerBetaTests.mm in Sources */,
13621360
5492E03520213FFC00B64F25 /* FSTSpecTests.mm in Sources */,
1363-
5492E03B2021401F00B64F25 /* FSTTestDispatchQueue.mm in Sources */,
13641361
5492E057202154AB00B64F25 /* FIRSnapshotMetadataTests.mm in Sources */,
13651362
54740A571FC914BA00713A1A /* secure_random_test.cc in Sources */,
13661363
5492E0BE2021555100B64F25 /* FSTMutationTests.mm in Sources */,
@@ -1388,7 +1385,6 @@
13881385
5492E07F202154EC00B64F25 /* FSTTransactionTests.mm in Sources */,
13891386
5492E075202154D600B64F25 /* FIRDatabaseTests.mm in Sources */,
13901387
5492E078202154D600B64F25 /* FIRWriteBatchTests.mm in Sources */,
1391-
5492E0432021441E00B64F25 /* FSTTestDispatchQueue.mm in Sources */,
13921388
);
13931389
runOnlyForDeploymentPostprocessing = 0;
13941390
};

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#import "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h"
2222
#import "Firestore/Source/API/FIRFirestore+Internal.h"
2323
#import "Firestore/Source/Core/FSTFirestoreClient.h"
24+
#import "Firestore/Source/Util/FSTDispatchQueue.h"
2425

2526
@interface FIRDatabaseTests : FSTIntegrationTestCase
2627
@end
@@ -926,7 +927,7 @@ - (void)testWriteStreamReconnectsAfterIdle {
926927
FIRFirestore *firestore = doc.firestore;
927928

928929
[self writeDocumentRef:doc data:@{@"foo" : @"bar"}];
929-
[self waitForIdleFirestore:firestore];
930+
[[self queueForFirestore:firestore] runDelayedCallbacksUntil:FSTTimerIDWriteStreamIdle];
930931
[self writeDocumentRef:doc data:@{@"foo" : @"bar"}];
931932
}
932933

@@ -935,7 +936,7 @@ - (void)testWatchStreamReconnectsAfterIdle {
935936
FIRFirestore *firestore = doc.firestore;
936937

937938
[self readSnapshotForRef:[self documentRef] requireOnline:YES];
938-
[self waitForIdleFirestore:firestore];
939+
[[self queueForFirestore:firestore] runDelayedCallbacksUntil:FSTTimerIDListenStreamIdle];
939940
[self readSnapshotForRef:[self documentRef] requireOnline:YES];
940941
}
941942

Firestore/Example/Tests/Integration/FSTStreamTests.mm

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
#import "Firestore/Example/Tests/Util/FSTHelpers.h"
2222
#import "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h"
23-
#import "Firestore/Example/Tests/Util/FSTTestDispatchQueue.h"
2423
#import "Firestore/Source/Auth/FSTEmptyCredentialsProvider.h"
2524
#import "Firestore/Source/Remote/FSTDatastore.h"
2625
#import "Firestore/Source/Remote/FSTStream.h"
@@ -133,7 +132,7 @@ @interface FSTStreamTests : XCTestCase
133132

134133
@implementation FSTStreamTests {
135134
dispatch_queue_t _testQueue;
136-
FSTTestDispatchQueue *_workerDispatchQueue;
135+
FSTDispatchQueue *_workerDispatchQueue;
137136
DatabaseInfo _databaseInfo;
138137
FSTEmptyCredentialsProvider *_credentials;
139138
FSTStreamStatusDelegate *_delegate;
@@ -150,7 +149,7 @@ DatabaseId database_id(util::MakeStringView([FSTIntegrationTestCase projectID]),
150149
DatabaseId::kDefaultDatabaseId);
151150

152151
_testQueue = dispatch_queue_create("FSTStreamTestWorkerQueue", DISPATCH_QUEUE_SERIAL);
153-
_workerDispatchQueue = [[FSTTestDispatchQueue alloc] initWithQueue:_testQueue];
152+
_workerDispatchQueue = [[FSTDispatchQueue alloc] initWithQueue:_testQueue];
154153

155154
_databaseInfo = DatabaseInfo(database_id, "test-key", util::MakeStringView(settings.host),
156155
settings.sslEnabled);
@@ -272,10 +271,14 @@ - (void)testStreamClosesWhenIdle {
272271
[writeStream writeHandshake];
273272
}];
274273

275-
[_delegate awaitNotificationFromBlock:^{
274+
[_workerDispatchQueue dispatchAsync:^{
276275
[writeStream markIdle];
276+
XCTAssertTrue(
277+
[_workerDispatchQueue containsDelayedCallbackWithTimerID:FSTTimerIDWriteStreamIdle]);
277278
}];
278279

280+
[_workerDispatchQueue runDelayedCallbacksUntil:FSTTimerIDWriteStreamIdle];
281+
279282
dispatch_sync(_testQueue, ^{
280283
XCTAssertFalse([writeStream isOpen]);
281284
});
@@ -299,7 +302,11 @@ - (void)testStreamCancelsIdleOnWrite {
299302
// Mark the stream idle, but immediately cancel the idle timer by issuing another write.
300303
[_delegate awaitNotificationFromBlock:^{
301304
[writeStream markIdle];
305+
XCTAssertTrue(
306+
[_workerDispatchQueue containsDelayedCallbackWithTimerID:FSTTimerIDWriteStreamIdle]);
302307
[writeStream writeMutations:_mutations];
308+
XCTAssertFalse(
309+
[_workerDispatchQueue containsDelayedCallbackWithTimerID:FSTTimerIDWriteStreamIdle]);
303310
}];
304311

305312
dispatch_sync(_testQueue, ^{
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Copyright 2018 Google
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#import "Firestore/Source/Util/FSTDispatchQueue.h"
18+
19+
#import <XCTest/XCTest.h>
20+
21+
#import "Firestore/Example/Tests/Util/XCTestCase+Await.h"
22+
23+
// In these generic tests the specific TimerIDs don't matter.
24+
static const FSTTimerID timerID1 = FSTTimerIDListenStreamConnection;
25+
static const FSTTimerID timerID2 = FSTTimerIDListenStreamIdle;
26+
static const FSTTimerID timerID3 = FSTTimerIDWriteStreamConnection;
27+
28+
@interface FSTDispatchQueueTests : XCTestCase
29+
@end
30+
31+
@implementation FSTDispatchQueueTests {
32+
FSTDispatchQueue *_queue;
33+
NSMutableArray *_completedSteps;
34+
NSArray *_expectedSteps;
35+
XCTestExpectation *_expectation;
36+
}
37+
38+
- (void)setUp {
39+
[super setUp];
40+
dispatch_queue_t dispatch_queue =
41+
dispatch_queue_create("FSTDispatchQueueTests", DISPATCH_QUEUE_SERIAL);
42+
_queue = [[FSTDispatchQueue alloc] initWithQueue:dispatch_queue];
43+
_completedSteps = [NSMutableArray array];
44+
_expectedSteps = nil;
45+
}
46+
47+
/**
48+
* Helper to return a block that adds @(n) to _completedSteps when run and fulfils _expectation if
49+
* the _completedSteps match the _expectedSteps.
50+
*/
51+
- (void (^)())blockForStep:(int)n {
52+
return ^void() {
53+
[self->_completedSteps addObject:@(n)];
54+
if (self->_expectedSteps && self->_completedSteps.count >= self->_expectedSteps.count) {
55+
XCTAssertEqualObjects(self->_completedSteps, self->_expectedSteps);
56+
[self->_expectation fulfill];
57+
}
58+
};
59+
}
60+
61+
- (void)testCanScheduleCallbacksInTheFuture {
62+
_expectation = [self expectationWithDescription:@"Expected steps"];
63+
_expectedSteps = @[ @1, @2, @3, @4 ];
64+
[_queue dispatchAsync:[self blockForStep:1]];
65+
[_queue dispatchAfterDelay:0.005 timerID:timerID1 block:[self blockForStep:4]];
66+
[_queue dispatchAfterDelay:0.001 timerID:timerID2 block:[self blockForStep:3]];
67+
[_queue dispatchAsync:[self blockForStep:2]];
68+
69+
[self awaitExpectations];
70+
}
71+
72+
- (void)testCanCancelDelayedCallbacks {
73+
_expectation = [self expectationWithDescription:@"Expected steps"];
74+
_expectedSteps = @[ @1, @3 ];
75+
// Queue everything from the queue to ensure nothing completes before we cancel.
76+
[_queue dispatchAsync:^{
77+
[_queue dispatchAsyncAllowingSameQueue:[self blockForStep:1]];
78+
FSTDelayedCallback *step2Timer =
79+
[_queue dispatchAfterDelay:.001 timerID:timerID1 block:[self blockForStep:2]];
80+
[_queue dispatchAfterDelay:.005 timerID:timerID2 block:[self blockForStep:3]];
81+
82+
XCTAssertTrue([_queue containsDelayedCallbackWithTimerID:timerID1]);
83+
[step2Timer cancel];
84+
XCTAssertFalse([_queue containsDelayedCallbackWithTimerID:timerID1]);
85+
}];
86+
87+
[self awaitExpectations];
88+
}
89+
90+
- (void)testCanManuallyDrainAllDelayedCallbacksForTesting {
91+
[_queue dispatchAsync:[self blockForStep:1]];
92+
[_queue dispatchAfterDelay:20 timerID:timerID1 block:[self blockForStep:4]];
93+
[_queue dispatchAfterDelay:10 timerID:timerID2 block:[self blockForStep:3]];
94+
[_queue dispatchAsync:[self blockForStep:2]];
95+
96+
[_queue runDelayedCallbacksUntil:FSTTimerIDAll];
97+
XCTAssertEqualObjects(_completedSteps, (@[ @1, @2, @3, @4 ]));
98+
}
99+
100+
- (void)testCanManuallyDrainSpecificDelayedCallbacksForTesting {
101+
[_queue dispatchAsync:[self blockForStep:1]];
102+
[_queue dispatchAfterDelay:20 timerID:timerID1 block:[self blockForStep:5]];
103+
[_queue dispatchAfterDelay:10 timerID:timerID2 block:[self blockForStep:3]];
104+
[_queue dispatchAfterDelay:15 timerID:timerID3 block:[self blockForStep:4]];
105+
[_queue dispatchAsync:[self blockForStep:2]];
106+
107+
[_queue runDelayedCallbacksUntil:timerID3];
108+
XCTAssertEqualObjects(_completedSteps, (@[ @1, @2, @3, @4 ]));
109+
}
110+
111+
@end

Firestore/Example/Tests/Util/FSTIntegrationTestCase.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
@class FIRFirestoreSettings;
2929
@class FIRQuery;
3030
@class FSTEventAccumulator;
31+
@class FSTDispatchQueue;
3132

3233
NS_ASSUME_NONNULL_BEGIN
3334

@@ -61,8 +62,6 @@ extern "C" {
6162
- (FIRCollectionReference *)collectionRefWithDocuments:
6263
(NSDictionary<NSString *, NSDictionary<NSString *, id> *> *)documents;
6364

64-
- (void)waitForIdleFirestore:(FIRFirestore *)firestore;
65-
6665
- (void)writeAllDocuments:(NSDictionary<NSString *, NSDictionary<NSString *, id> *> *)documents
6766
toCollection:(FIRCollectionReference *)collection;
6867

@@ -87,6 +86,8 @@ extern "C" {
8786

8887
- (void)enableNetwork;
8988

89+
- (FSTDispatchQueue *)queueForFirestore:(FIRFirestore *)firestore;
90+
9091
/**
9192
* "Blocks" the current thread/run loop until the block returns YES.
9293
* Should only be called on the main thread.

Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#import "Firestore/Source/Util/FSTDispatchQueue.h"
3131

3232
#import "Firestore/Example/Tests/Util/FSTEventAccumulator.h"
33-
#import "Firestore/Example/Tests/Util/FSTTestDispatchQueue.h"
3433

3534
#include "Firestore/core/src/firebase/firestore/model/database_id.h"
3635
#include "Firestore/core/src/firebase/firestore/util/string_apple.h"
@@ -133,7 +132,7 @@ + (FIRFirestoreSettings *)settings {
133132
- (FIRFirestore *)firestoreWithProjectID:(NSString *)projectID {
134133
NSString *persistenceKey = [NSString stringWithFormat:@"db%lu", (unsigned long)_firestores.count];
135134

136-
FSTTestDispatchQueue *workerDispatchQueue = [FSTTestDispatchQueue
135+
FSTDispatchQueue *workerDispatchQueue = [FSTDispatchQueue
137136
queueWith:dispatch_queue_create("com.google.firebase.firestore", DISPATCH_QUEUE_SERIAL)];
138137

139138
FSTEmptyCredentialsProvider *credentialsProvider = [[FSTEmptyCredentialsProvider alloc] init];
@@ -155,14 +154,6 @@ - (FIRFirestore *)firestoreWithProjectID:(NSString *)projectID {
155154
return firestore;
156155
}
157156

158-
- (void)waitForIdleFirestore:(FIRFirestore *)firestore {
159-
XCTestExpectation *expectation = [self expectationWithDescription:@"idle"];
160-
// Note that we wait on any task that is scheduled with a delay of 60s. Currently, the idle
161-
// timeout is the only task that uses this delay.
162-
[((FSTTestDispatchQueue *)firestore.workerDispatchQueue) fulfillOnExecution:expectation];
163-
[self awaitExpectations];
164-
}
165-
166157
- (void)shutdownFirestore:(FIRFirestore *)firestore {
167158
[firestore shutdownWithCompletion:[self completionForExpectationWithName:@"shutdown"]];
168159
[self awaitExpectations];
@@ -289,6 +280,10 @@ - (void)enableNetwork {
289280
[self awaitExpectations];
290281
}
291282

283+
- (FSTDispatchQueue *)queueForFirestore:(FIRFirestore *)firestore {
284+
return firestore.workerDispatchQueue;
285+
}
286+
292287
- (void)waitUntil:(BOOL (^)())predicate {
293288
NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
294289
double waitSeconds = [self defaultExpectationWaitSeconds];

0 commit comments

Comments
 (0)