aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Example/Tests/Integration
diff options
context:
space:
mode:
authorGravatar Michael Lehenbauer <mikelehen@gmail.com>2018-02-15 16:17:44 -0800
committerGravatar GitHub <noreply@github.com>2018-02-15 16:17:44 -0800
commit81ee594e325a922a91557d82563132f22977c947 (patch)
tree89ea78b6ccc77fa2f11e1c6b1fa40f3c8d54a3b2 /Firestore/Example/Tests/Integration
parentfd9fd271d0dba3935a6f5611a1554f2c59b696af (diff)
DispatchQueue delayed callback improvements + testing (#784)
Basically a port of https://github.com/firebase/firebase-js-sdk/commit/a1e346ff93c6cbcc0a1b3b33f0fbc3a7b66e7e12 and https://github.com/firebase/firebase-js-sdk/commit/fce4168309f42aa038125f39818fbf654b65b05f * 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.
Diffstat (limited to 'Firestore/Example/Tests/Integration')
-rw-r--r--Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm5
-rw-r--r--Firestore/Example/Tests/Integration/FSTStreamTests.mm15
2 files changed, 14 insertions, 6 deletions
diff --git a/Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm b/Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm
index 3b6a67e..751e7ff 100644
--- a/Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm
+++ b/Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm
@@ -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
@@ -926,7 +927,7 @@
FIRFirestore *firestore = doc.firestore;
[self writeDocumentRef:doc data:@{@"foo" : @"bar"}];
- [self waitForIdleFirestore:firestore];
+ [[self queueForFirestore:firestore] runDelayedCallbacksUntil:FSTTimerIDWriteStreamIdle];
[self writeDocumentRef:doc data:@{@"foo" : @"bar"}];
}
@@ -935,7 +936,7 @@
FIRFirestore *firestore = doc.firestore;
[self readSnapshotForRef:[self documentRef] requireOnline:YES];
- [self waitForIdleFirestore:firestore];
+ [[self queueForFirestore:firestore] runDelayedCallbacksUntil:FSTTimerIDListenStreamIdle];
[self readSnapshotForRef:[self documentRef] requireOnline:YES];
}
diff --git a/Firestore/Example/Tests/Integration/FSTStreamTests.mm b/Firestore/Example/Tests/Integration/FSTStreamTests.mm
index 6259aff..a36361a 100644
--- a/Firestore/Example/Tests/Integration/FSTStreamTests.mm
+++ b/Firestore/Example/Tests/Integration/FSTStreamTests.mm
@@ -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"
@@ -133,7 +132,7 @@ using firebase::firestore::model::DatabaseId;
@implementation FSTStreamTests {
dispatch_queue_t _testQueue;
- FSTTestDispatchQueue *_workerDispatchQueue;
+ FSTDispatchQueue *_workerDispatchQueue;
DatabaseInfo _databaseInfo;
FSTEmptyCredentialsProvider *_credentials;
FSTStreamStatusDelegate *_delegate;
@@ -150,7 +149,7 @@ using firebase::firestore::model::DatabaseId;
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);
@@ -272,10 +271,14 @@ using firebase::firestore::model::DatabaseId;
[writeStream writeHandshake];
}];
- [_delegate awaitNotificationFromBlock:^{
+ [_workerDispatchQueue dispatchAsync:^{
[writeStream markIdle];
+ XCTAssertTrue(
+ [_workerDispatchQueue containsDelayedCallbackWithTimerID:FSTTimerIDWriteStreamIdle]);
}];
+ [_workerDispatchQueue runDelayedCallbacksUntil:FSTTimerIDWriteStreamIdle];
+
dispatch_sync(_testQueue, ^{
XCTAssertFalse([writeStream isOpen]);
});
@@ -299,7 +302,11 @@ using firebase::firestore::model::DatabaseId;
// 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, ^{