Files
firebase-ios-sdk/Example/Database/Tests/Helpers/FDevice.m
T
Benoit St-Pierre 54659e8d99 Database Interop Rollforward (#2095)
* Register Database with Interop

+ Add AuthInterop dependency
+ Have Database register with Interop component container
+ Add weak dependency on Auth
~ Cleaned up imports

* Use Interop for Auth token fetching

+ Use macro to get auth component
~ Change `getTokenForcingRefresh:withCallback:` call to use Interop component version of Auth
~ Clean up imports

* Implement necessary protocols

+ Added FIRComponentRegistrant and FIRDatabaseNilProtocol to FIRDatabase

* Squash of my previous local commits for Database Interop

Register Database with Interop:

  + Add AuthInterop dependency
  + Have Database register with Interop component container
  + Add weak dependency on Auth
  ~ Cleaned up imports

Use Interop for Auth token fetching:

  + Use macro to get auth component
  ~ Change `getTokenForcingRefresh:withCallback:` call to use Interop component version of Auth
  ~ Clean up imports

Implement necessary protocols:

  + Added FIRComponentRegistrant and FIRDatabaseNilProtocol to FIRDatabase

Clean up Database tests:

  - Removed all unnecessary header files
  ~ Ran style.sh across all the tests

Cleaned Up project file:

  Some header removals were missed in the last commit.

Sorted some test files

Fix Database Fake App Tests:

  + Added container property
  + Added an Auth fake in the container
  + Added the Shared utils files to the necessary targets
  + Added a missing XCTest reference in a test that didn't compile for me

* Revert "Squash of my previous local commits for Database Interop"

This reverts commit c0d0421237.

* Cleaned Up project file

Some header removals were missed in the last commit.

* Sorted some test files

* Fix Database Fake App Tests

+ Added container property
+ Added an Auth fake in the container
+ Added the Shared utils files to the necessary targets
+ Added a missing XCTest reference in a test that didn't compile for me

* PR Feedback Changes

+ Created new FIRDatabaseComponent class to encapsulate instance creation
+ Updated FAuthTokenProvider to only use an auth instance rather than an app.

* PR Feedback Follow-Up

- Removed FIRDatabase registration code

* pod deintegrate

* Move instance management

Somes tests may still be out of date.

* Fix Auth integration test

* pod deintegrate -- again

* PR Feedback

* PR Feedback

Added the FIRComponentLifecycleMaintainer protocol to FIRDatabaseComponent

* Update Firebase/Database/Api/FIRDatabaseComponent.m

Missed some small changes

* Get integration tests compiling

* Fix some tests

* Fixed more tests

Component needs to be cacheable in order to get the appWIllBeDeleted callback.

* Update target memberships

* Revert project file changes

* Add FIRAuthInteropFake for broken targets

* PR feedback

* Spacing and Style

* Moved `instances` to ivar

* Simplify FIRDatabaseDictionary

It's now keyed on the URL with the app being implied since each app will get its own `FIRDatabaseComponent`

* Fix Database Integration Tests

Have the FakeApp cache DB instances
Use the Full host/URL path to cache DB instances
Simplified shared scheme

```
Test Suite 'Database_IntegrationTests_iOS.xctest' passed at 2018-11-20 07:09:30.520.
	 Executed 326 tests, with 0 failures (0 unexpected) in 66.251 (66.528) seconds
Test Suite 'All tests' passed at 2018-11-20 07:09:30.522.
	 Executed 326 tests, with 0 failures (0 unexpected) in 66.251 (66.530) seconds
```

* Clarify defaultApp use
2018-11-22 06:44:42 -05:00

136 lines
3.7 KiB
Objective-C

/*
* Copyright 2017 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import <XCTest/XCTest.h>
#import "FDevice.h"
#import <FirebaseDatabase/FIRDatabaseReference.h>
#import "FRepoManager.h"
#import "FIRDatabaseReference_Private.h"
#import "FIRDatabaseConfig_Private.h"
#import "SenTest+FWaiter.h"
#import "FTestHelpers.h"
@interface FDevice() {
FIRDatabaseConfig * config;
NSString *url;
BOOL isOnline;
BOOL disposed;
}
@end
@implementation FDevice
- (id)initOnline {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
return [self initOnlineWithUrl:[ref description]];
}
- (id)initOffline {
FIRDatabaseReference * ref = [FTestHelpers getRandomNode];
return [self initOfflineWithUrl:[ref description]];
}
- (id)initOnlineWithUrl:(NSString *)firebaseUrl {
return [self initWithUrl:firebaseUrl andOnline:YES];
}
- (id)initOfflineWithUrl:(NSString *)firebaseUrl {
return [self initWithUrl:firebaseUrl andOnline:NO];
}
static NSUInteger deviceId = 0;
- (id)initWithUrl:(NSString *)firebaseUrl andOnline:(BOOL)online {
self = [super init];
if (self) {
config = [FTestHelpers configForName:[NSString stringWithFormat:@"device-%lu", deviceId++]];
config.persistenceEnabled = YES;
url = firebaseUrl;
isOnline = online;
}
return self;
}
- (void) dealloc
{
if (!self->disposed) {
[NSException raise:NSInternalInconsistencyException format:@"Forgot to dispose device"];
}
}
- (void) dispose {
// TODO: clear persistence
[FRepoManager disposeRepos:self->config];
self->disposed = YES;
}
- (void)goOffline {
isOnline = NO;
[FRepoManager interrupt:config];
}
- (void)goOnline {
isOnline = YES;
[FRepoManager resume:config];
}
- (void)restartOnline {
@autoreleasepool {
[FRepoManager disposeRepos:config];
isOnline = YES;
}
}
- (void)restartOffline {
@autoreleasepool {
[FRepoManager disposeRepos:config];
isOnline = NO;
}
}
// Waits for us to connect and then does an extra round-trip to make sure all initial state restoration is completely done.
- (void)waitForIdleUsingWaiter:(XCTest*)waiter {
[self do:^(FIRDatabaseReference *ref) {
__block BOOL connected = NO;
FIRDatabaseHandle handle = [[ref.root child:@".info/connected"] observeEventType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot *snapshot) {
connected = [snapshot.value boolValue];
}];
[waiter waitUntil:^BOOL { return connected; }];
[ref.root removeObserverWithHandle:handle];
// HACK: Do a deep setPriority (which we expect to fail because there's no data there) to do a no-op roundtrip.
__block BOOL done = NO;
[[ref.root child:@"ENTOHTNUHOE/ONTEHNUHTOE"] setPriority:@"blah" withCompletionBlock:^(NSError *error, FIRDatabaseReference *ref) {
done = YES;
}];
[waiter waitUntil:^BOOL { return done; }];
}];
}
- (void)do:(void (^)(FIRDatabaseReference *))action {
@autoreleasepool {
FIRDatabaseReference *ref = [[[[FIRDatabaseReference alloc] initWithConfig:self->config] database] referenceFromURL:self->url];
if (!isOnline) {
[FRepoManager interrupt:config];
}
action(ref);
}
}
@end