@@ -362,42 +362,35 @@ - (void)testOnceValueFiresExactlyOnce {
362362}
363363
364364- (void )testOnceChildAddedFiresExactlyOnce {
365- __block int badCount = 0 ;
365+ for (int i = 0 ; i < 100 ; i++) {
366+ FIRDatabaseReference* path = [FTestHelpers getRandomNode ];
367+ __block BOOL firstCall = YES ;
366368
367- // for(int i = 0; i < 100; i++) {
369+ __block BOOL done = NO ;
368370
369- FIRDatabaseReference* path = [FTestHelpers getRandomNode ];
370- __block BOOL firstCall = YES ;
371-
372- __block BOOL done = NO ;
373-
374- [path observeSingleEventOfType: FIRDataEventTypeChildAdded
375- withBlock: ^(FIRDataSnapshot* snapshot) {
376- XCTAssertTrue (firstCall, @" Properly saw first call" );
377- firstCall = NO ;
378- XCTAssertEqualObjects (@42 , [snapshot value ], @" Properly saw node value" );
379- XCTAssertEqualObjects (@" foo" , [snapshot key ],
380- @" Properly saw the first node" );
381- if (![[snapshot value ] isEqual: @42 ]) {
382- exit (-1 );
383- badCount = badCount + 1 ;
384- }
385-
386- done = YES ;
387- }];
388-
389- [[path child: @" foo" ] setValue: @42 ];
390- [[path child: @" bar" ] setValue: @84 ]; // XXX FIXME sometimes this event fires first
391- [[path child: @" foo" ] setValue: @168 ];
371+ [path observeSingleEventOfType: FIRDataEventTypeChildAdded
372+ withBlock: ^(FIRDataSnapshot* snapshot) {
373+ XCTAssertTrue (firstCall, @" Properly saw first call" );
374+ firstCall = NO ;
375+ XCTAssertEqualObjects (@42 , [snapshot value ], @" Properly saw node value" );
376+ XCTAssertEqualObjects (@" foo" , [snapshot key ],
377+ @" Properly saw the first node" );
378+ if (![[snapshot value ] isEqual: @42 ]) {
379+ exit (-1 );
380+ }
392381
393- // [path setValue:nil withCompletionBlock:^(BOOL status) { done = YES; }];
394- [self waitUntil: ^BOOL {
395- return done;
396- }];
382+ done = YES ;
383+ }];
397384
398- // }
385+ [[path child: @" foo" ] setValue: @42 ];
386+ [[path child: @" bar" ] setValue: @84 ]; // XXX FIXME sometimes this event fires first
387+ [[path child: @" foo" ] setValue: @168 ];
399388
400- NSLog (@" BADCOUNT: %d " , badCount);
389+ // [path setValue:nil withCompletionBlock:^(BOOL status) { done = YES; }];
390+ [self waitUntil: ^BOOL {
391+ return done;
392+ }];
393+ }
401394}
402395
403396- (void )testOnceValueFiresExactlyOnceEvenIfThereIsASetInsideCallback {
0 commit comments