|
22 | 22 | #import "Firestore/Example/Tests/Util/FSTEventAccumulator.h"
|
23 | 23 | #import "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h"
|
24 | 24 | #import "Firestore/Source/API/FIRFirestore+Internal.h"
|
| 25 | +#import "Firestore/Source/Core/FSTFirestoreClient.h" |
| 26 | +#include "Firestore/core/test/firebase/firestore/testutil/app_testing.h" |
| 27 | + |
| 28 | +namespace testutil = firebase::firestore::testutil; |
25 | 29 |
|
26 | 30 | using firebase::firestore::util::TimerId;
|
27 | 31 |
|
@@ -1315,4 +1319,66 @@ - (void)testClearPersistenceWhileRunningFails {
|
1315 | 1319 | [self awaitExpectations];
|
1316 | 1320 | }
|
1317 | 1321 |
|
| 1322 | +- (void)testRestartFirestoreLeadsToNewInstance { |
| 1323 | + FIRApp *app = testutil::AppForUnitTesting(util::MakeString([FSTIntegrationTestCase projectID])); |
| 1324 | + FIRFirestore *firestore = [FIRFirestore firestoreForApp:app]; |
| 1325 | + FIRFirestore *sameInstance = [FIRFirestore firestoreForApp:app]; |
| 1326 | + firestore.settings = [FSTIntegrationTestCase settings]; |
| 1327 | + |
| 1328 | + XCTAssertEqual(firestore, sameInstance); |
| 1329 | + |
| 1330 | + NSDictionary<NSString *, id> *data = |
| 1331 | + @{@"owner" : @{@"name" : @"Jonny", @"email" : @"abc@xyz.com"}}; |
| 1332 | + [self writeDocumentRef:[firestore documentWithPath:@"abc/123"] data:data]; |
| 1333 | + |
| 1334 | + [self shutdownFirestore:firestore]; |
| 1335 | + |
| 1336 | + // Create a new instance, check it's a different instance. |
| 1337 | + FIRFirestore *newInstance = [FIRFirestore firestoreForApp:app]; |
| 1338 | + newInstance.settings = [FSTIntegrationTestCase settings]; |
| 1339 | + XCTAssertNotEqual(firestore, newInstance); |
| 1340 | + |
| 1341 | + // New instance still functions. |
| 1342 | + FIRDocumentSnapshot *snapshot = |
| 1343 | + [self readDocumentForRef:[newInstance documentWithPath:@"abc/123"]]; |
| 1344 | + XCTAssertTrue([data isEqualToDictionary:[snapshot data]]); |
| 1345 | +} |
| 1346 | + |
| 1347 | +- (void)testAppDeleteLeadsToFirestoreShutdown { |
| 1348 | + FIRApp *app = testutil::AppForUnitTesting(util::MakeString([FSTIntegrationTestCase projectID])); |
| 1349 | + FIRFirestore *firestore = [FIRFirestore firestoreForApp:app]; |
| 1350 | + firestore.settings = [FSTIntegrationTestCase settings]; |
| 1351 | + NSDictionary<NSString *, id> *data = |
| 1352 | + @{@"owner" : @{@"name" : @"Jonny", @"email" : @"abc@xyz.com"}}; |
| 1353 | + [self writeDocumentRef:[firestore documentWithPath:@"abc/123"] data:data]; |
| 1354 | + |
| 1355 | + [self deleteApp:app]; |
| 1356 | + |
| 1357 | + FSTFirestoreClient *client = firestore.wrapped->client(); |
| 1358 | + XCTAssertTrue([client isShutdown]); |
| 1359 | +} |
| 1360 | + |
| 1361 | +- (void)testShutdownCanBeCalledMultipleTimes { |
| 1362 | + FIRApp *app = testutil::AppForUnitTesting(util::MakeString([FSTIntegrationTestCase projectID])); |
| 1363 | + FIRFirestore *firestore = [FIRFirestore firestoreForApp:app]; |
| 1364 | + |
| 1365 | + [firestore shutdownWithCompletion:[self completionForExpectationWithName:@"Shutdown1"]]; |
| 1366 | + [self awaitExpectations]; |
| 1367 | + XCTAssertThrowsSpecific( |
| 1368 | + { |
| 1369 | + [firestore disableNetworkWithCompletion:^(NSError *error){ |
| 1370 | + }]; |
| 1371 | + }, |
| 1372 | + NSException, @"The client has already been shutdown."); |
| 1373 | + |
| 1374 | + [firestore shutdownWithCompletion:[self completionForExpectationWithName:@"Shutdown2"]]; |
| 1375 | + [self awaitExpectations]; |
| 1376 | + XCTAssertThrowsSpecific( |
| 1377 | + { |
| 1378 | + [firestore enableNetworkWithCompletion:^(NSError *error){ |
| 1379 | + }]; |
| 1380 | + }, |
| 1381 | + NSException, @"The client has already been shutdown."); |
| 1382 | +} |
| 1383 | + |
1318 | 1384 | @end
|
0 commit comments