Skip to content

DispatchQueue delayed callback improvements + testing #784

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

Merged
merged 3 commits into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions Firestore/Example/Firestore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@
5492E03320213FFC00B64F25 /* FSTSyncEngineTestDriver.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E02E20213FFC00B64F25 /* FSTSyncEngineTestDriver.mm */; };
5492E03420213FFC00B64F25 /* FSTMemorySpecTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E02F20213FFC00B64F25 /* FSTMemorySpecTests.mm */; };
5492E03520213FFC00B64F25 /* FSTSpecTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E03020213FFC00B64F25 /* FSTSpecTests.mm */; };
5492E03B2021401F00B64F25 /* FSTTestDispatchQueue.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0362021401E00B64F25 /* FSTTestDispatchQueue.mm */; };
5492E03C2021401F00B64F25 /* XCTestCase+Await.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0372021401E00B64F25 /* XCTestCase+Await.mm */; };
5492E03D2021401F00B64F25 /* FSTAssertTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0382021401E00B64F25 /* FSTAssertTests.mm */; };
5492E03E2021401F00B64F25 /* FSTEventAccumulator.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0392021401F00B64F25 /* FSTEventAccumulator.mm */; };
5492E03F2021401F00B64F25 /* FSTHelpers.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E03A2021401F00B64F25 /* FSTHelpers.mm */; };
5492E041202143E700B64F25 /* FSTEventAccumulator.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0392021401F00B64F25 /* FSTEventAccumulator.mm */; };
5492E0422021440500B64F25 /* FSTHelpers.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E03A2021401F00B64F25 /* FSTHelpers.mm */; };
5492E0432021441E00B64F25 /* FSTTestDispatchQueue.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0362021401E00B64F25 /* FSTTestDispatchQueue.mm */; };
5492E0442021457E00B64F25 /* XCTestCase+Await.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E0372021401E00B64F25 /* XCTestCase+Await.mm */; };
5492E050202154AA00B64F25 /* FIRCollectionReferenceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E045202154AA00B64F25 /* FIRCollectionReferenceTests.mm */; };
5492E051202154AA00B64F25 /* FIRQueryTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5492E046202154AA00B64F25 /* FIRQueryTests.mm */; };
Expand Down Expand Up @@ -133,6 +131,7 @@
6003F5BA195388D20070C39A /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 6003F5B8195388D20070C39A /* InfoPlist.strings */; };
6ED54761B845349D43DB6B78 /* Pods_Firestore_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 75A6FE51C1A02DF38F62FAAD /* Pods_Firestore_Example.framework */; };
71719F9F1E33DC2100824A3D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 71719F9D1E33DC2100824A3D /* LaunchScreen.storyboard */; };
7346E61D20325C6900FD6CEF /* FSTDispatchQueueTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7346E61C20325C6900FD6CEF /* FSTDispatchQueueTests.mm */; };
873B8AEB1B1F5CCA007FD442 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 873B8AEA1B1F5CCA007FD442 /* Main.storyboard */; };
AB356EF7200EA5EB0089B766 /* field_value_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB356EF6200EA5EB0089B766 /* field_value_test.cc */; };
AB380CFB2019388600D97691 /* target_id_generator_test.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB380CF82019382300D97691 /* target_id_generator_test.cc */; };
Expand Down Expand Up @@ -225,7 +224,6 @@
5492E02E20213FFC00B64F25 /* FSTSyncEngineTestDriver.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTSyncEngineTestDriver.mm; sourceTree = "<group>"; };
5492E02F20213FFC00B64F25 /* FSTMemorySpecTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTMemorySpecTests.mm; sourceTree = "<group>"; };
5492E03020213FFC00B64F25 /* FSTSpecTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTSpecTests.mm; sourceTree = "<group>"; };
5492E0362021401E00B64F25 /* FSTTestDispatchQueue.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTTestDispatchQueue.mm; sourceTree = "<group>"; };
5492E0372021401E00B64F25 /* XCTestCase+Await.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "XCTestCase+Await.mm"; sourceTree = "<group>"; };
5492E0382021401E00B64F25 /* FSTAssertTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTAssertTests.mm; sourceTree = "<group>"; };
5492E0392021401F00B64F25 /* FSTEventAccumulator.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTEventAccumulator.mm; sourceTree = "<group>"; };
Expand Down Expand Up @@ -332,6 +330,7 @@
6003F5B9195388D20070C39A /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
69F6A10DBD6187489481CD76 /* Pods_Firestore_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
71719F9E1E33DC2100824A3D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
7346E61C20325C6900FD6CEF /* FSTDispatchQueueTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FSTDispatchQueueTests.mm; sourceTree = "<group>"; };
75A6FE51C1A02DF38F62FAAD /* Pods_Firestore_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Firestore_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
873B8AEA1B1F5CCA007FD442 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Main.storyboard; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
8E002F4AD5D9B6197C940847 /* Firestore.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = Firestore.podspec; path = ../Firestore.podspec; sourceTree = "<group>"; };
Expand All @@ -358,7 +357,6 @@
B686F2B02024FFD70028D6BE /* resource_path_test.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = resource_path_test.cc; sourceTree = "<group>"; };
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>"; };
D3CC3DC5338DCAF43A211155 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
D5B259DAA9149B80D6245B57 /* FSTTestDispatchQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FSTTestDispatchQueue.h; sourceTree = "<group>"; };
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>"; };
DE03B2E91F2149D600A30B9C /* Firestore_IntegrationTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Firestore_IntegrationTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
DE03B3621F215E1600A30B9C /* CAcert.pem */ = {isa = PBXFileReference; lastKnownFileType = text; path = CAcert.pem; sourceTree = "<group>"; };
Expand Down Expand Up @@ -715,10 +713,9 @@
5492E03A2021401F00B64F25 /* FSTHelpers.mm */,
54E9281E1F33950B00C1953E /* FSTIntegrationTestCase.h */,
5491BC711FB44593008B3588 /* FSTIntegrationTestCase.mm */,
D5B259DAA9149B80D6245B57 /* FSTTestDispatchQueue.h */,
5492E0362021401E00B64F25 /* FSTTestDispatchQueue.mm */,
54E9282A1F339CAD00C1953E /* XCTestCase+Await.h */,
5492E0372021401E00B64F25 /* XCTestCase+Await.mm */,
7346E61C20325C6900FD6CEF /* FSTDispatchQueueTests.mm */,
);
path = Util;
sourceTree = "<group>";
Expand Down Expand Up @@ -1263,6 +1260,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7346E61D20325C6900FD6CEF /* FSTDispatchQueueTests.mm in Sources */,
DE2EF0881F3D0B6E003D0CDC /* FSTTreeSortedDictionaryTests.m in Sources */,
ABE6637A201FA81900ED349A /* database_id_test.cc in Sources */,
5492E0AF2021552D00B64F25 /* FSTReferenceSetTests.mm in Sources */,
Expand Down Expand Up @@ -1348,7 +1346,6 @@
5492E052202154AB00B64F25 /* FIRGeoPointTests.mm in Sources */,
5492E0C72021557E00B64F25 /* FSTSerializerBetaTests.mm in Sources */,
5492E03520213FFC00B64F25 /* FSTSpecTests.mm in Sources */,
5492E03B2021401F00B64F25 /* FSTTestDispatchQueue.mm in Sources */,
5492E057202154AB00B64F25 /* FIRSnapshotMetadataTests.mm in Sources */,
54740A571FC914BA00713A1A /* secure_random_test.cc in Sources */,
5492E0BE2021555100B64F25 /* FSTMutationTests.mm in Sources */,
Expand Down Expand Up @@ -1376,7 +1373,6 @@
5492E07F202154EC00B64F25 /* FSTTransactionTests.mm in Sources */,
5492E075202154D600B64F25 /* FIRDatabaseTests.mm in Sources */,
5492E078202154D600B64F25 /* FIRWriteBatchTests.mm in Sources */,
5492E0432021441E00B64F25 /* FSTTestDispatchQueue.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
5 changes: 3 additions & 2 deletions Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#import "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h"
#import "Firestore/Source/API/FIRFirestore+Internal.h"
#import "Firestore/Source/Core/FSTFirestoreClient.h"
#import "Firestore/Source/Util/FSTDispatchQueue.h"

@interface FIRDatabaseTests : FSTIntegrationTestCase
@end
Expand Down Expand Up @@ -926,7 +927,7 @@ - (void)testWriteStreamReconnectsAfterIdle {
FIRFirestore *firestore = doc.firestore;

[self writeDocumentRef:doc data:@{@"foo" : @"bar"}];
[self waitForIdleFirestore:firestore];
[[self queueForFirestore:firestore] runDelayedCallbacksUntil:FSTTimerIDWriteStreamIdle];
[self writeDocumentRef:doc data:@{@"foo" : @"bar"}];
}

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

[self readSnapshotForRef:[self documentRef] requireOnline:YES];
[self waitForIdleFirestore:firestore];
[[self queueForFirestore:firestore] runDelayedCallbacksUntil:FSTTimerIDListenStreamIdle];
[self readSnapshotForRef:[self documentRef] requireOnline:YES];
}

Expand Down
15 changes: 11 additions & 4 deletions Firestore/Example/Tests/Integration/FSTStreamTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

#import "Firestore/Example/Tests/Util/FSTHelpers.h"
#import "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h"
#import "Firestore/Example/Tests/Util/FSTTestDispatchQueue.h"
#import "Firestore/Source/Auth/FSTEmptyCredentialsProvider.h"
#import "Firestore/Source/Remote/FSTDatastore.h"
#import "Firestore/Source/Remote/FSTStream.h"
Expand Down Expand Up @@ -133,7 +132,7 @@ @interface FSTStreamTests : XCTestCase

@implementation FSTStreamTests {
dispatch_queue_t _testQueue;
FSTTestDispatchQueue *_workerDispatchQueue;
FSTDispatchQueue *_workerDispatchQueue;
DatabaseInfo _databaseInfo;
FSTEmptyCredentialsProvider *_credentials;
FSTStreamStatusDelegate *_delegate;
Expand All @@ -150,7 +149,7 @@ DatabaseId database_id(util::MakeStringView([FSTIntegrationTestCase projectID]),
DatabaseId::kDefaultDatabaseId);

_testQueue = dispatch_queue_create("FSTStreamTestWorkerQueue", DISPATCH_QUEUE_SERIAL);
_workerDispatchQueue = [[FSTTestDispatchQueue alloc] initWithQueue:_testQueue];
_workerDispatchQueue = [[FSTDispatchQueue alloc] initWithQueue:_testQueue];

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

[_delegate awaitNotificationFromBlock:^{
[_workerDispatchQueue dispatchAsync:^{
[writeStream markIdle];
XCTAssertTrue(
[_workerDispatchQueue containsDelayedCallbackWithTimerID:FSTTimerIDWriteStreamIdle]);
}];

[_workerDispatchQueue runDelayedCallbacksUntil:FSTTimerIDWriteStreamIdle];

dispatch_sync(_testQueue, ^{
XCTAssertFalse([writeStream isOpen]);
});
Expand All @@ -299,7 +302,11 @@ - (void)testStreamCancelsIdleOnWrite {
// Mark the stream idle, but immediately cancel the idle timer by issuing another write.
[_delegate awaitNotificationFromBlock:^{
[writeStream markIdle];
XCTAssertTrue(
[_workerDispatchQueue containsDelayedCallbackWithTimerID:FSTTimerIDWriteStreamIdle]);
[writeStream writeMutations:_mutations];
XCTAssertFalse(
[_workerDispatchQueue containsDelayedCallbackWithTimerID:FSTTimerIDWriteStreamIdle]);
}];

dispatch_sync(_testQueue, ^{
Expand Down
111 changes: 111 additions & 0 deletions Firestore/Example/Tests/Util/FSTDispatchQueueTests.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright 2018 Google
*
* 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 "Firestore/Source/Util/FSTDispatchQueue.h"

#import <XCTest/XCTest.h>

#import "Firestore/Example/Tests/Util/XCTestCase+Await.h"

// In these generic tests the specific TimerIDs don't matter.
static const FSTTimerID timerID1 = FSTTimerIDListenStreamConnection;
static const FSTTimerID timerID2 = FSTTimerIDListenStreamIdle;
static const FSTTimerID timerID3 = FSTTimerIDWriteStreamConnection;

@interface FSTDispatchQueueTests : XCTestCase
@end

@implementation FSTDispatchQueueTests {
FSTDispatchQueue *_queue;
NSMutableArray *_completedSteps;
NSArray *_expectedSteps;
XCTestExpectation *_expectation;
}

- (void)setUp {
[super setUp];
dispatch_queue_t dispatch_queue =
dispatch_queue_create("FSTDispatchQueueTests", DISPATCH_QUEUE_SERIAL);
_queue = [[FSTDispatchQueue alloc] initWithQueue:dispatch_queue];
_completedSteps = [NSMutableArray array];
_expectedSteps = nil;
}

/**
* Helper to return a block that adds @(n) to _completedSteps when run and fulfils _expectation if
* the _completedSteps match the _expectedSteps.
*/
- (void (^)())blockForStep:(int)n {
return ^void() {
[self->_completedSteps addObject:@(n)];
if (self->_expectedSteps && self->_completedSteps.count >= self->_expectedSteps.count) {
XCTAssertEqualObjects(self->_completedSteps, self->_expectedSteps);
[self->_expectation fulfill];
}
};
}

- (void)testCanScheduleCallbacksInTheFuture {
_expectation = [self expectationWithDescription:@"Expected steps"];
_expectedSteps = @[ @1, @2, @3, @4 ];
[_queue dispatchAsync:[self blockForStep:1]];
[_queue dispatchAfterDelay:0.005 timerID:timerID1 block:[self blockForStep:4]];
[_queue dispatchAfterDelay:0.001 timerID:timerID2 block:[self blockForStep:3]];
[_queue dispatchAsync:[self blockForStep:2]];

[self awaitExpectations];
}

- (void)testCanCancelDelayedCallbacks {
_expectation = [self expectationWithDescription:@"Expected steps"];
_expectedSteps = @[ @1, @3 ];
// Queue everything from the queue to ensure nothing completes before we cancel.
[_queue dispatchAsync:^{
[_queue dispatchAsyncAllowingSameQueue:[self blockForStep:1]];
FSTDelayedCallback *step2Timer =
[_queue dispatchAfterDelay:.001 timerID:timerID1 block:[self blockForStep:2]];
[_queue dispatchAfterDelay:.005 timerID:timerID2 block:[self blockForStep:3]];

XCTAssertTrue([_queue containsDelayedCallbackWithTimerID:timerID1]);
[step2Timer cancel];
XCTAssertFalse([_queue containsDelayedCallbackWithTimerID:timerID1]);
}];

[self awaitExpectations];
}

- (void)testCanManuallyDrainAllDelayedCallbacksForTesting {
[_queue dispatchAsync:[self blockForStep:1]];
[_queue dispatchAfterDelay:20 timerID:timerID1 block:[self blockForStep:4]];
[_queue dispatchAfterDelay:10 timerID:timerID2 block:[self blockForStep:3]];
[_queue dispatchAsync:[self blockForStep:2]];

[_queue runDelayedCallbacksUntil:FSTTimerIDAll];
XCTAssertEqualObjects(_completedSteps, (@[ @1, @2, @3, @4 ]));
}

- (void)testCanManuallyDrainSpecificDelayedCallbacksForTesting {
[_queue dispatchAsync:[self blockForStep:1]];
[_queue dispatchAfterDelay:20 timerID:timerID1 block:[self blockForStep:5]];
[_queue dispatchAfterDelay:10 timerID:timerID2 block:[self blockForStep:3]];
[_queue dispatchAfterDelay:15 timerID:timerID3 block:[self blockForStep:4]];
[_queue dispatchAsync:[self blockForStep:2]];

[_queue runDelayedCallbacksUntil:timerID3];
XCTAssertEqualObjects(_completedSteps, (@[ @1, @2, @3, @4 ]));
}

@end
5 changes: 3 additions & 2 deletions Firestore/Example/Tests/Util/FSTIntegrationTestCase.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
@class FIRFirestoreSettings;
@class FIRQuery;
@class FSTEventAccumulator;
@class FSTDispatchQueue;

NS_ASSUME_NONNULL_BEGIN

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

- (void)waitForIdleFirestore:(FIRFirestore *)firestore;

- (void)writeAllDocuments:(NSDictionary<NSString *, NSDictionary<NSString *, id> *> *)documents
toCollection:(FIRCollectionReference *)collection;

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

- (void)enableNetwork;

- (FSTDispatchQueue *)queueForFirestore:(FIRFirestore *)firestore;

/**
* "Blocks" the current thread/run loop until the block returns YES.
* Should only be called on the main thread.
Expand Down
15 changes: 5 additions & 10 deletions Firestore/Example/Tests/Util/FSTIntegrationTestCase.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#import "Firestore/Source/Util/FSTDispatchQueue.h"

#import "Firestore/Example/Tests/Util/FSTEventAccumulator.h"
#import "Firestore/Example/Tests/Util/FSTTestDispatchQueue.h"

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

FSTTestDispatchQueue *workerDispatchQueue = [FSTTestDispatchQueue
FSTDispatchQueue *workerDispatchQueue = [FSTDispatchQueue
queueWith:dispatch_queue_create("com.google.firebase.firestore", DISPATCH_QUEUE_SERIAL)];

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

- (void)waitForIdleFirestore:(FIRFirestore *)firestore {
XCTestExpectation *expectation = [self expectationWithDescription:@"idle"];
// Note that we wait on any task that is scheduled with a delay of 60s. Currently, the idle
// timeout is the only task that uses this delay.
[((FSTTestDispatchQueue *)firestore.workerDispatchQueue) fulfillOnExecution:expectation];
[self awaitExpectations];
}

- (void)shutdownFirestore:(FIRFirestore *)firestore {
[firestore shutdownWithCompletion:[self completionForExpectationWithName:@"shutdown"]];
[self awaitExpectations];
Expand Down Expand Up @@ -289,6 +280,10 @@ - (void)enableNetwork {
[self awaitExpectations];
}

- (FSTDispatchQueue *)queueForFirestore:(FIRFirestore *)firestore {
return firestore.workerDispatchQueue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this function pays for itself. Why not just access this property directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because only this file has this at the top:

@interface FIRFirestore (Testing)
@property(nonatomic, strong) FSTDispatchQueue *workerDispatchQueue;
@end

I'm open to exposing this property to tests differently if you have a more-preferred way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other cases we've added the testing category in a separate header and just included that in the places where it's required. However this whole thing is going to be rewritten in C++ where that pattern doesn't apply so carry on.

}

- (void)waitUntil:(BOOL (^)())predicate {
NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
double waitSeconds = [self defaultExpectationWaitSeconds];
Expand Down
Loading