From edd6f60a7385f9280c371df273703f6e104e325f Mon Sep 17 00:00:00 2001 From: Konstantin Varlamov Date: Thu, 10 May 2018 20:16:50 -0400 Subject: Firestore: use C++ Executor for user queue. (#1238) FSTDispatchQueue enforces serial execution, which is inappropriate for user queue, because a user may configure usage of a concurrent queue in settings, breaking FSTDispatchQueue invariants. Instead, use C++ ExecutorLibdispatch directly. --- .../Example/Tests/Core/FSTQueryListenerTests.mm | 33 +++++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'Firestore/Example') diff --git a/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm b/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm index 7ae9704..5629075 100644 --- a/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm +++ b/Firestore/Example/Tests/Core/FSTQueryListenerTests.mm @@ -15,6 +15,7 @@ */ #import +#include #import "Firestore/Source/Core/FSTEventManager.h" #import "Firestore/Source/Core/FSTQuery.h" @@ -23,23 +24,29 @@ #import "Firestore/Source/Model/FSTDocumentSet.h" #import "Firestore/Source/Remote/FSTRemoteEvent.h" #import "Firestore/Source/Util/FSTAsyncQueryListener.h" -#import "Firestore/Source/Util/FSTDispatchQueue.h" #import "Firestore/Example/Tests/Util/FSTHelpers.h" +#include "Firestore/core/src/firebase/firestore/util/executor_libdispatch.h" +#include "absl/memory/memory.h" + +using firebase::firestore::util::internal::ExecutorLibdispatch; using firebase::firestore::model::DocumentKeySet; NS_ASSUME_NONNULL_BEGIN @interface FSTQueryListenerTests : XCTestCase -@property(nonatomic, strong, readonly) FSTDispatchQueue *asyncQueue; @end -@implementation FSTQueryListenerTests +@implementation FSTQueryListenerTests { + std::unique_ptr _executor; +} - (void)setUp { - _asyncQueue = [FSTDispatchQueue - queueWith:dispatch_queue_create("FSTQueryListenerTests Queue", DISPATCH_QUEUE_SERIAL)]; + // TODO(varconst): moving this test to C++, it should be possible to store Executor as a value, + // not a pointer, and initialize it in the constructor. + _executor = absl::make_unique( + dispatch_queue_create("FSTQueryListenerTests Queue", DISPATCH_QUEUE_SERIAL)); } - (void)testRaisesCollectionEvents { @@ -131,12 +138,12 @@ NS_ASSUME_NONNULL_BEGIN FSTDocument *doc1 = FSTTestDoc("rooms/Eros", 3, @{@"name" : @"Eros"}, NO); FSTDocument *doc2 = FSTTestDoc("rooms/Eros", 4, @{@"name" : @"Eros2"}, NO); - __block FSTAsyncQueryListener *listener = [[FSTAsyncQueryListener alloc] - initWithDispatchQueue:self.asyncQueue - snapshotHandler:^(FSTViewSnapshot *snapshot, NSError *error) { - [accum addObject:snapshot]; - [listener mute]; - }]; + __block FSTAsyncQueryListener *listener = + [[FSTAsyncQueryListener alloc] initWithExecutor:_executor.get() + snapshotHandler:^(FSTViewSnapshot *snapshot, NSError *error) { + [accum addObject:snapshot]; + [listener mute]; + }]; FSTView *view = [[FSTView alloc] initWithQuery:query remoteDocuments:DocumentKeySet{}]; FSTViewSnapshot *viewSnapshot1 = FSTTestApplyChanges(view, @[ doc1 ], nil); @@ -148,9 +155,7 @@ NS_ASSUME_NONNULL_BEGIN // Drain queue XCTestExpectation *expectation = [self expectationWithDescription:@"Queue drained"]; - [self.asyncQueue dispatchAsync:^{ - [expectation fulfill]; - }]; + _executor->Execute([=] { [expectation fulfill]; }); [self waitForExpectationsWithTimeout:4.0 handler:^(NSError *_Nullable expectationError) { -- cgit v1.2.3