diff options
author | Konstantin Varlamov <var-const@users.noreply.github.com> | 2018-05-10 20:16:50 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-10 20:16:50 -0400 |
commit | edd6f60a7385f9280c371df273703f6e104e325f (patch) | |
tree | 89b2d18d4f5d4253dd6b87842d7a0182aabd50de /Firestore/Example/Tests | |
parent | 8cde81689dcfc74c9b59e088bbe00f95ca4bf68d (diff) |
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.
Diffstat (limited to 'Firestore/Example/Tests')
-rw-r--r-- | Firestore/Example/Tests/Core/FSTQueryListenerTests.mm | 33 |
1 files changed, 19 insertions, 14 deletions
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 <XCTest/XCTest.h> +#include <memory> #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<ExecutorLibdispatch> _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<ExecutorLibdispatch>( + 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) { |