@@ -365,29 +365,6 @@ - (void)testRunsTransactionsOnNonexistentDoc {
365
365
[[[tt withNonexistentDoc ] runWithStages: @[ set1, set2 ]] expectDoc: @{@" foo" : @" bar2" }];
366
366
}
367
367
368
- - (void )testGetDocuments {
369
- FIRFirestore *firestore = [self firestore ];
370
- FIRDocumentReference *doc = [[firestore collectionWithPath: @" spaces" ] documentWithAutoID ];
371
- [self writeDocumentRef: doc data: @{@" foo" : @1 , @" desc" : @" Stuff" , @" owner" : @" Jonny" }];
372
-
373
- XCTestExpectation *expectation = [self expectationWithDescription: @" transaction" ];
374
- [firestore
375
- runTransactionWithBlock: ^id _Nullable (FIRTransaction *transaction, NSError **error) {
376
- [transaction getDocument: doc error: error];
377
- XCTAssertNil (*error);
378
- return @YES ;
379
- }
380
- completion: ^(id _Nullable result, NSError *_Nullable error) {
381
- XCTAssertNil (result);
382
- // We currently require every document read to also be written.
383
- // TODO(b/34879758): Fix this check once we drop that requirement.
384
- XCTAssertNotNil (error);
385
- XCTAssertEqual (error.code , FIRFirestoreErrorCodeInvalidArgument);
386
- [expectation fulfill ];
387
- }];
388
- [self awaitExpectations ];
389
- }
390
-
391
368
- (void )testSetDocumentWithMerge {
392
369
FIRFirestore *firestore = [self firestore ];
393
370
FIRDocumentReference *doc = [[firestore collectionWithPath: @" towns" ] documentWithAutoID ];
@@ -414,8 +391,7 @@ - (void)testSetDocumentWithMerge {
414
391
- (void )testIncrementTransactionally {
415
392
// A barrier to make sure every transaction reaches the same spot.
416
393
dispatch_semaphore_t writeBarrier = dispatch_semaphore_create (0 );
417
- auto counter_unique = absl::make_unique<std::atomic_int32_t >(0 );
418
- auto counter = counter_unique.get ();
394
+ auto counter = std::make_shared<std::atomic_int>(0 );
419
395
420
396
FIRFirestore *firestore = [self firestore ];
421
397
FIRDocumentReference *doc = [[firestore collectionWithPath: @" counters" ] documentWithAutoID ];
@@ -460,8 +436,7 @@ - (void)testIncrementTransactionally {
460
436
- (void )testUpdateTransactionally {
461
437
// A barrier to make sure every transaction reaches the same spot.
462
438
dispatch_semaphore_t writeBarrier = dispatch_semaphore_create (0 );
463
- auto counter_unique = absl::make_unique<std::atomic_int32_t >(0 );
464
- auto counter = counter_unique.get ();
439
+ auto counter = std::make_shared<std::atomic_int>(0 );
465
440
466
441
FIRFirestore *firestore = [self firestore ];
467
442
FIRDocumentReference *doc = [[firestore collectionWithPath: @" counters" ] documentWithAutoID ];
@@ -482,7 +457,7 @@ - (void)testUpdateTransactionally {
482
457
// Once all of the transactions have read, allow the first write. There should be 3
483
458
// initial transaction runs.
484
459
if (nowStarted == total) {
485
- XCTAssertEqual (( int )(* counter), 3 );
460
+ XCTAssertEqual (counter-> load ( ), 3 );
486
461
dispatch_semaphore_signal (writeBarrier);
487
462
}
488
463
@@ -501,17 +476,18 @@ - (void)testUpdateTransactionally {
501
476
502
477
[self awaitExpectations ];
503
478
// There should be a maximum of 3 retries: once for the 2nd update, and twice for the 3rd update.
504
- XCTAssertLessThanOrEqual (( int )(* counter), 6 );
479
+ XCTAssertLessThanOrEqual (counter-> load ( ), 6 );
505
480
// Now all transaction should be completed, so check the result.
506
481
FIRDocumentSnapshot *snapshot = [self readDocumentForRef: doc];
507
482
XCTAssertEqualObjects (snapshot[@" count" ], @(5.0 + total));
508
483
XCTAssertEqualObjects (@" yes" , snapshot[@" other" ]);
509
484
}
510
485
511
- - (void )testHandleReadingOneDocAndWritingAnother {
486
+ - (void )testRetriesWhenDocumentThatWasReadWithoutBeingWrittenChanges {
512
487
FIRFirestore *firestore = [self firestore ];
513
488
FIRDocumentReference *doc1 = [[firestore collectionWithPath: @" counters" ] documentWithAutoID ];
514
489
FIRDocumentReference *doc2 = [[firestore collectionWithPath: @" counters" ] documentWithAutoID ];
490
+ auto counter = std::make_shared<std::atomic_int>(0 );
515
491
516
492
[self writeDocumentRef: doc1 data: @{@" count" : @(15.0 )}];
517
493
@@ -521,6 +497,7 @@ - (void)testHandleReadingOneDocAndWritingAnother {
521
497
XCTestExpectation *expectation = [self expectationWithDescription: @" transaction" ];
522
498
[firestore
523
499
runTransactionWithBlock: ^id _Nullable (FIRTransaction *transaction, NSError **error) {
500
+ ++(*counter);
524
501
// Get the first doc.
525
502
[transaction getDocument: doc1 error: error];
526
503
XCTAssertNil (*error);
@@ -543,28 +520,19 @@ - (void)testHandleReadingOneDocAndWritingAnother {
543
520
return nil ;
544
521
}
545
522
completion: ^(id _Nullable result, NSError *_Nullable error) {
546
- // We currently require every document read to also be written.
547
- // TODO(b/34879758): Add this check back once we drop that.
548
- // NSError *error = nil;
549
- // FIRDocument *snapshot = [transaction getDocument:doc1 error:&error];
550
- // XCTAssertNil(error);
551
- // XCTAssertEquals(0, tries);
552
- // XCTAssertEqualObjects(@(1234), snapshot[@"count"]);
553
- // snapshot = [transaction getDocument:doc2 error:&error];
554
- // XCTAssertNil(error);
555
- // XCTAssertEqualObjects(@(16), snapshot[@"count"]);
556
- XCTAssertNotNil (error);
557
- XCTAssertEqual (error.code , FIRFirestoreErrorCodeInvalidArgument);
523
+ XCTAssertNil (error);
524
+ XCTAssertEqual (counter->load (), 2 );
558
525
[expectation fulfill ];
559
526
}];
560
527
[self awaitExpectations ];
528
+ FIRDocumentSnapshot *snapshot = [self readDocumentForRef: doc1];
529
+ XCTAssertEqualObjects (snapshot[@" count" ], @(1234 ));
561
530
}
562
531
563
532
- (void )testReadingADocTwiceWithDifferentVersions {
564
533
FIRFirestore *firestore = [self firestore ];
565
534
FIRDocumentReference *doc = [[firestore collectionWithPath: @" counters" ] documentWithAutoID ];
566
- auto counter_unique = absl::make_unique<std::atomic_int32_t >(0 );
567
- auto counter = counter_unique.get ();
535
+ auto counter = std::make_shared<std::atomic_int>(0 );
568
536
569
537
[self writeDocumentRef: doc data: @{@" count" : @(15.0 )}];
570
538
@@ -640,32 +608,32 @@ - (void)testReadAndUpdateNonExistentDocumentWithExternalWrite {
640
608
[self awaitExpectations ];
641
609
}
642
610
643
- - (void )testCannotHaveAGetWithoutMutations {
611
+ - (void )testCanHaveGetsWithoutMutations {
644
612
FIRFirestore *firestore = [self firestore ];
645
613
FIRDocumentReference *doc = [[firestore collectionWithPath: @" foo" ] documentWithAutoID ];
614
+ FIRDocumentReference *doc2 = [[firestore collectionWithPath: @" foo" ] documentWithAutoID ];
615
+
646
616
[self writeDocumentRef: doc data: @{@" foo" : @" bar" }];
647
617
XCTestExpectation *expectation = [self expectationWithDescription: @" transaction" ];
648
618
[firestore
649
619
runTransactionWithBlock: ^id _Nullable (FIRTransaction *transaction, NSError **error) {
650
- FIRDocumentSnapshot *snapshot = [transaction getDocument: doc error: error];
651
- XCTAssertTrue (snapshot.exists );
652
- XCTAssertNil (*error);
620
+ [transaction getDocument: doc2 error: error];
621
+ [transaction getDocument: doc error: error];
653
622
return nil ;
654
623
}
655
624
completion: ^(id _Nullable result, NSError *_Nullable error) {
656
- // We currently require every document read to also be written.
657
- // TODO(b/34879758): Fix this check once we drop that requirement.
658
- XCTAssertNotNil (error);
659
- XCTAssertEqual (error.code , FIRFirestoreErrorCodeInvalidArgument);
625
+ XCTAssertNil (error);
660
626
[expectation fulfill ];
661
627
}];
662
628
[self awaitExpectations ];
629
+ FIRDocumentSnapshot *snapshot = [self readDocumentForRef: doc];
630
+ XCTAssertEqualObjects (snapshot[@" foo" ], @" bar" );
663
631
}
664
632
665
633
- (void )testDoesNotRetryOnPermanentError {
666
634
FIRFirestore *firestore = [self firestore ];
667
- auto counter_unique = absl::make_unique <std::atomic_int32_t >(0 );
668
- auto counter = counter_unique. get ();
635
+ auto counter = std::make_shared <std::atomic_int >(0 );
636
+
669
637
// Make a transaction that should fail with a permanent error
670
638
XCTestExpectation *expectation = [self expectationWithDescription: @" transaction" ];
671
639
[firestore
@@ -682,7 +650,7 @@ - (void)testDoesNotRetryOnPermanentError {
682
650
[expectation fulfill ];
683
651
XCTAssertNotNil (error);
684
652
XCTAssertEqual (error.code , FIRFirestoreErrorCodeInvalidArgument);
685
- XCTAssertEqual (( int )(* counter), 1 );
653
+ XCTAssertEqual (counter-> load ( ), 1 );
686
654
}];
687
655
[self awaitExpectations ];
688
656
}
@@ -705,8 +673,7 @@ - (void)testSuccessWithNoTransactionOperations {
705
673
- (void )testCancellationOnError {
706
674
FIRFirestore *firestore = [self firestore ];
707
675
FIRDocumentReference *doc = [[firestore collectionWithPath: @" towns" ] documentWithAutoID ];
708
- auto counter_unique = absl::make_unique<std::atomic_int32_t >(0 );
709
- auto counter = counter_unique.get ();
676
+ auto counter = std::make_shared<std::atomic_int>(0 );
710
677
XCTestExpectation *expectation = [self expectationWithDescription: @" transaction" ];
711
678
[firestore
712
679
runTransactionWithBlock: ^id _Nullable (FIRTransaction *transaction, NSError **error) {
@@ -724,7 +691,7 @@ - (void)testCancellationOnError {
724
691
[expectation fulfill ];
725
692
}];
726
693
[self awaitExpectations ];
727
- XCTAssertEqual (( int )(* counter), 1 );
694
+ XCTAssertEqual (counter-> load ( ), 1 );
728
695
FIRDocumentSnapshot *snapshot = [self readDocumentForRef: doc];
729
696
XCTAssertFalse (snapshot.exists );
730
697
}
0 commit comments