Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Database Interop" #2093

Merged
merged 1 commit into from Nov 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion Example/Database/Tests/Helpers/FDevice.h
Expand Up @@ -18,7 +18,6 @@

@class FIRDatabaseReference;
@class SenTest;
@class XCTest;

@interface FDevice : NSObject
- (id)initOnline;
Expand Down
2 changes: 1 addition & 1 deletion Example/Database/Tests/Helpers/FDevice.m
Expand Up @@ -58,7 +58,7 @@ - (id)initOfflineWithUrl:(NSString *)firebaseUrl {
- (id)initWithUrl:(NSString *)firebaseUrl andOnline:(BOOL)online {
self = [super init];
if (self) {
config = [FTestHelpers configForName:[NSString stringWithFormat:@"device-%lu", deviceId++]];
config = [FIRDatabaseConfig configForName:[NSString stringWithFormat:@"device-%lu", deviceId++]];
config.persistenceEnabled = YES;
url = firebaseUrl;
isOnline = online;
Expand Down
2 changes: 0 additions & 2 deletions Example/Database/Tests/Helpers/FIRFakeApp.h
Expand Up @@ -16,7 +16,6 @@

#import <Foundation/Foundation.h>

@class FIRComponentContainer;
@class FIRFakeOptions;

@interface FIRFakeApp : NSObject
Expand All @@ -25,5 +24,4 @@

@property(nonatomic, readonly) FIRFakeOptions *options;
@property(nonatomic, copy, readonly) NSString *name;
@property(nonatomic, readonly) FIRComponentContainer *container;
@end
52 changes: 18 additions & 34 deletions Example/Database/Tests/Helpers/FIRFakeApp.m
Expand Up @@ -16,49 +16,33 @@

#import "FIRFakeApp.h"

#import "FIRAuthInteropFake.h"
#import "FIRComponentTestUtilities.h"
#import "FIRDatabaseComponent.h"

@interface FIRFakeOptions: NSObject
@property(nonatomic, readonly, copy) NSString *databaseURL;
- (instancetype)initWithURL:(NSString *)url;
- (instancetype) initWithURL:(NSString *)url;
@end

@implementation FIRFakeOptions
- (instancetype)initWithURL:(NSString *)url {
self = [super init];
if (self) {
_databaseURL = url;
}
return self;
- (instancetype) initWithURL:(NSString *)url {
self = [super init];
if (self) {
self->_databaseURL = url;
}
return self;
}
@end

@interface FIRDatabaseComponent (Internal)
- (instancetype)initWithApp:(FIRApp *)app;
@end

@implementation FIRFakeApp

- (instancetype)initWithName:(NSString *)name URL:(NSString *)url {
self = [super init];
if (self) {
_name = name;
_options = [[FIRFakeOptions alloc] initWithURL:url];
_Nullable id (^authBlock)(FIRComponentContainer *, BOOL *) =
^(FIRComponentContainer *container, BOOL *isCacheable) {
return [[FIRAuthInteropFake alloc] initWithToken:nil userID:nil error:nil];
};
FIRComponentCreationBlock databaseBlock =
^id _Nullable(FIRComponentContainer *container, BOOL *isCacheable) {
return [[FIRDatabaseComponent alloc] initWithApp:container.app];
};
NSDictionary<NSString *, FIRComponentCreationBlock> *components =
@{NSStringFromProtocol(@protocol(FIRAuthInterop)) : authBlock,
NSStringFromProtocol(@protocol(FIRDatabaseProvider)) : databaseBlock};
_container = [[FIRComponentContainer alloc] initWithApp:(FIRApp *)self components:components];
}
return self;
- (instancetype) initWithName:(NSString *)name URL:(NSString *)url {
self = [super init];
if (self) {
self->_name = name;
self->_options = [[FIRFakeOptions alloc] initWithURL:url];
}
return self;
}

- (void)getTokenForcingRefresh:(BOOL)forceRefresh withCallback:(void (^)(NSString *_Nullable token, NSError *_Nullable error))callback {
callback(nil, nil);
}
@end
2 changes: 0 additions & 2 deletions Example/Database/Tests/Helpers/FTestHelpers.h
Expand Up @@ -28,8 +28,6 @@
#define PATH(__path) [FPath pathWithString:(__path)]

@interface FTestHelpers : XCTestCase
+ (FIRDatabaseConfig *) defaultConfig;
+ (FIRDatabaseConfig *) configForName:(NSString *)name;
+ (FIRDatabaseReference *) getRandomNode;
+ (FIRDatabaseReference *) getRandomNodeWithoutPersistence;
+ (FTupleFirebase *) getRandomNodePair;
Expand Down
181 changes: 79 additions & 102 deletions Example/Database/Tests/Helpers/FTestHelpers.m
Expand Up @@ -15,141 +15,118 @@
*/

#import "FTestHelpers.h"

#import <FirebaseAuthInterop/FIRAuthInterop.h>
#import <FirebaseCore/FIRAppInternal.h>
#import <FirebaseCore/FIRComponent.h>
#import <FirebaseCore/FIRComponentContainer.h>
#import <FirebaseCore/FIROptions.h>

#import "FConstants.h"
#import "FIRAuthInteropFake.h"
#import <FirebaseCore/FIRApp.h>
#import <FirebaseCore/FIROptions.h>
#import "FIRDatabaseConfig_Private.h"
#import "FTestAuthTokenGenerator.h"

@implementation FTestHelpers

+ (NSTimeInterval)waitUntil:(BOOL (^)())predicate timeout:(NSTimeInterval)seconds {
NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
NSDate *timeoutDate = [NSDate dateWithTimeIntervalSinceNow:seconds];
NSTimeInterval timeoutTime = [timeoutDate timeIntervalSinceReferenceDate];
NSTimeInterval currentTime;

for (currentTime = [NSDate timeIntervalSinceReferenceDate];
!predicate() && currentTime < timeoutTime;
currentTime = [NSDate timeIntervalSinceReferenceDate]) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
}
+ (NSTimeInterval) waitUntil:(BOOL (^)())predicate timeout:(NSTimeInterval)seconds {
NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
NSDate *timeoutDate = [NSDate dateWithTimeIntervalSinceNow:seconds];
NSTimeInterval timeoutTime = [timeoutDate timeIntervalSinceReferenceDate];
NSTimeInterval currentTime;

NSTimeInterval finish = [NSDate timeIntervalSinceReferenceDate];
for (currentTime = [NSDate timeIntervalSinceReferenceDate];
!predicate() && currentTime < timeoutTime;
currentTime = [NSDate timeIntervalSinceReferenceDate]) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
}

NSAssert(currentTime <= timeoutTime, @"Timed out");
NSTimeInterval finish = [NSDate timeIntervalSinceReferenceDate];

return (finish - start);
}
NSAssert(currentTime <= timeoutTime, @"Timed out");

+ (FIRDatabaseConfig *)defaultConfig {
return [self configForName:@"default"];
return (finish - start);
}

+ (FIRDatabaseConfig *)configForName:(NSString *)name {
id<FIRAuthInterop> auth = [[FIRAuthInteropFake alloc] initWithToken:nil userID:nil error:nil];
id<FAuthTokenProvider> authTokenProvider = [FAuthTokenProvider authTokenProviderWithAuth:auth];
return [[FIRDatabaseConfig alloc] initWithSessionIdentifier:name
authTokenProvider:authTokenProvider];
}
+ (NSArray*) getRandomNodes:(int)num persistence:(BOOL)persistence {
static dispatch_once_t pred = 0;
static NSMutableArray *persistenceRefs = nil;
static NSMutableArray *noPersistenceRefs = nil;
dispatch_once(&pred, ^{
persistenceRefs = [[NSMutableArray alloc] init];
noPersistenceRefs = [[NSMutableArray alloc] init];
// Uncomment the following line to run tests against a background thread
//[Firebase setDispatchQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
});

NSMutableArray *refs = (persistence) ? persistenceRefs : noPersistenceRefs;

id<FAuthTokenProvider> authTokenProvider = [FAuthTokenProvider authTokenProviderForApp:[FIRApp defaultApp]];

while (num > refs.count) {
NSString *sessionIdentifier = [NSString stringWithFormat:@"test-config-%@persistence-%lu", (persistence) ? @"" : @"no-", refs.count];
FIRDatabaseConfig *config = [[FIRDatabaseConfig alloc] initWithSessionIdentifier:sessionIdentifier authTokenProvider:authTokenProvider];
config.persistenceEnabled = persistence;
FIRDatabaseReference * ref = [[FIRDatabaseReference alloc] initWithConfig:config];
[refs addObject:ref];
}

+ (NSArray *)getRandomNodes:(int)num persistence:(BOOL)persistence {
static dispatch_once_t pred = 0;
static NSMutableArray *persistenceRefs = nil;
static NSMutableArray *noPersistenceRefs = nil;
dispatch_once(&pred, ^{
persistenceRefs = [[NSMutableArray alloc] init];
noPersistenceRefs = [[NSMutableArray alloc] init];
// Uncomment the following line to run tests against a background thread
//[Firebase setDispatchQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
});

NSMutableArray *refs = (persistence) ? persistenceRefs : noPersistenceRefs;

id<FIRAuthInterop> auth = [[FIRAuthInteropFake alloc] initWithToken:nil userID:nil error:nil];
id<FAuthTokenProvider> authTokenProvider = [FAuthTokenProvider authTokenProviderWithAuth:auth];

while (num > refs.count) {
NSString *sessionIdentifier =
[NSString stringWithFormat:@"test-config-%@persistence-%lu", (persistence) ? @"" : @"no-",
refs.count];
FIRDatabaseConfig *config =
[[FIRDatabaseConfig alloc] initWithSessionIdentifier:sessionIdentifier
authTokenProvider:authTokenProvider];
config.persistenceEnabled = persistence;
FIRDatabaseReference *ref = [[FIRDatabaseReference alloc] initWithConfig:config];
[refs addObject:ref];
}

NSMutableArray *results = [[NSMutableArray alloc] init];
NSString *name = nil;
for (int i = 0; i < num; ++i) {
FIRDatabaseReference *ref = [refs objectAtIndex:i];
if (!name) {
name = [ref childByAutoId].key;
NSMutableArray* results = [[NSMutableArray alloc] init];
NSString* name = nil;
for (int i = 0; i < num; ++i) {
FIRDatabaseReference * ref = [refs objectAtIndex:i];
if (!name) {
name = [ref childByAutoId].key;
}
[results addObject:[ref child:name]];
}
[results addObject:[ref child:name]];
}
return results;
return results;
}

// Helpers
+ (FIRDatabaseReference *)getRandomNode {
NSArray *refs = [self getRandomNodes:1 persistence:YES];
return [refs objectAtIndex:0];
+ (FIRDatabaseReference *) getRandomNode {
NSArray* refs = [self getRandomNodes:1 persistence:YES];
return [refs objectAtIndex:0];
}

+ (FIRDatabaseReference *)getRandomNodeWithoutPersistence {
NSArray *refs = [self getRandomNodes:1 persistence:NO];
return refs[0];
+ (FIRDatabaseReference *) getRandomNodeWithoutPersistence {
NSArray* refs = [self getRandomNodes:1 persistence:NO];
return refs[0];
}

+ (FTupleFirebase *)getRandomNodePair {
NSArray *refs = [self getRandomNodes:2 persistence:YES];
+ (FTupleFirebase *) getRandomNodePair {
NSArray* refs = [self getRandomNodes:2 persistence:YES];

FTupleFirebase *tuple = [[FTupleFirebase alloc] init];
tuple.one = [refs objectAtIndex:0];
tuple.two = [refs objectAtIndex:1];
FTupleFirebase* tuple = [[FTupleFirebase alloc] init];
tuple.one = [refs objectAtIndex:0];
tuple.two = [refs objectAtIndex:1];

return tuple;
return tuple;
}

+ (FTupleFirebase *)getRandomNodePairWithoutPersistence {
NSArray *refs = [self getRandomNodes:2 persistence:NO];
+ (FTupleFirebase *) getRandomNodePairWithoutPersistence {
NSArray* refs = [self getRandomNodes:2 persistence:NO];

FTupleFirebase *tuple = [[FTupleFirebase alloc] init];
tuple.one = refs[0];
tuple.two = refs[1];
FTupleFirebase* tuple = [[FTupleFirebase alloc] init];
tuple.one = refs[0];
tuple.two = refs[1];

return tuple;
return tuple;
}

+ (FTupleFirebase *)getRandomNodeTriple {
NSArray *refs = [self getRandomNodes:3 persistence:YES];
FTupleFirebase *triple = [[FTupleFirebase alloc] init];
triple.one = [refs objectAtIndex:0];
triple.two = [refs objectAtIndex:1];
triple.three = [refs objectAtIndex:2];
+ (FTupleFirebase *) getRandomNodeTriple {
NSArray* refs = [self getRandomNodes:3 persistence:YES];
FTupleFirebase* triple = [[FTupleFirebase alloc] init];
triple.one = [refs objectAtIndex:0];
triple.two = [refs objectAtIndex:1];
triple.three = [refs objectAtIndex:2];

return triple;
return triple;
}

+ (id<FNode>)leafNodeOfSize:(NSUInteger)size {
NSMutableString *string = [NSMutableString string];
NSString *pattern = @"abdefghijklmopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for (NSUInteger i = 0; i < size - pattern.length; i = i + pattern.length) {
[string appendString:pattern];
}
NSUInteger remainingLength = size - string.length;
[string appendString:[pattern substringToIndex:remainingLength]];
return [FSnapshotUtilities nodeFrom:string];
NSMutableString *string = [NSMutableString string];
NSString *pattern = @"abdefghijklmopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for (NSUInteger i = 0; i < size - pattern.length; i = i + pattern.length) {
[string appendString:pattern];
}
NSUInteger remainingLength = size - string.length;
[string appendString:[pattern substringToIndex:remainingLength]];
return [FSnapshotUtilities nodeFrom:string];
}

@end
2 changes: 1 addition & 1 deletion Example/Database/Tests/Integration/FData.m
Expand Up @@ -2529,7 +2529,7 @@ - (void) testUpdateAfterChildSet {

- (void) testDeltaSyncNoDataUpdatesAfterReconnect {
FIRDatabaseReference *ref = [FTestHelpers getRandomNode];
FIRDatabaseConfig *cfg = [FTestHelpers configForName:@"test-config"];
FIRDatabaseConfig *cfg = [FIRDatabaseConfig configForName:@"test-config"];
FIRDatabaseReference * ref2 = [[[FIRDatabaseReference alloc] initWithConfig:cfg] child:ref.key];
__block id data = @{ @"a": @1, @"b": @2, @"c": @{ @".priority": @3, @".value": @3}, @"d": @4 };
[self waitForCompletionOf:ref setValue:data];
Expand Down
8 changes: 4 additions & 4 deletions Example/Database/Tests/Integration/FDotInfo.m
Expand Up @@ -51,7 +51,7 @@ - (void) testCanWatchInfoConnected {
}

- (void) testInfoConnectedGoesToFalseOnDisconnect {
FIRDatabaseConfig *cfg = [FTestHelpers configForName:@"test-config"];
FIRDatabaseConfig *cfg = [FIRDatabaseConfig configForName:@"test-config"];
FIRDatabaseReference * rootRef = [[FIRDatabaseReference alloc] initWithConfig:cfg];
__block BOOL everConnected = NO;
__block NSMutableString *connectedHistory = [[NSMutableString alloc] init];
Expand All @@ -78,7 +78,7 @@ - (void) testInfoConnectedGoesToFalseOnDisconnect {
}

- (void) testInfoServerTimeOffset {
FIRDatabaseConfig *cfg = [FTestHelpers configForName:@"test-config"];
FIRDatabaseConfig *cfg = [FIRDatabaseConfig configForName:@"test-config"];
FIRDatabaseReference * ref = [[FIRDatabaseReference alloc] initWithConfig:cfg];

// make sure childByAutoId works
Expand All @@ -103,8 +103,8 @@ - (void) testInfoServerTimeOffset {
}

- (void) testManualConnectionManagement {
FIRDatabaseConfig *cfg = [FTestHelpers configForName:@"test-config"];
FIRDatabaseConfig *altCfg = [FTestHelpers configForName:@"alt-config"];
FIRDatabaseConfig *cfg = [FIRDatabaseConfig configForName:@"test-config"];
FIRDatabaseConfig *altCfg = [FIRDatabaseConfig configForName:@"alt-config"];

FIRDatabaseReference * ref = [[FIRDatabaseReference alloc] initWithConfig:cfg];
FIRDatabaseReference * refAlt = [[FIRDatabaseReference alloc] initWithConfig:altCfg];
Expand Down