Skip to content

Commit 50d27eb

Browse files
authored
Revert "Database Interop (#1865)" (#2093)
This reverts commit 4090195.
1 parent 4090195 commit 50d27eb

26 files changed

+338
-482
lines changed

Example/Database/Tests/Helpers/FDevice.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
@class FIRDatabaseReference;
2020
@class SenTest;
21-
@class XCTest;
2221

2322
@interface FDevice : NSObject
2423
- (id)initOnline;

Example/Database/Tests/Helpers/FDevice.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ - (id)initOfflineWithUrl:(NSString *)firebaseUrl {
5858
- (id)initWithUrl:(NSString *)firebaseUrl andOnline:(BOOL)online {
5959
self = [super init];
6060
if (self) {
61-
config = [FTestHelpers configForName:[NSString stringWithFormat:@"device-%lu", deviceId++]];
61+
config = [FIRDatabaseConfig configForName:[NSString stringWithFormat:@"device-%lu", deviceId++]];
6262
config.persistenceEnabled = YES;
6363
url = firebaseUrl;
6464
isOnline = online;

Example/Database/Tests/Helpers/FIRFakeApp.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#import <Foundation/Foundation.h>
1818

19-
@class FIRComponentContainer;
2019
@class FIRFakeOptions;
2120

2221
@interface FIRFakeApp : NSObject
@@ -25,5 +24,4 @@
2524

2625
@property(nonatomic, readonly) FIRFakeOptions *options;
2726
@property(nonatomic, copy, readonly) NSString *name;
28-
@property(nonatomic, readonly) FIRComponentContainer *container;
2927
@end

Example/Database/Tests/Helpers/FIRFakeApp.m

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,33 @@
1616

1717
#import "FIRFakeApp.h"
1818

19-
#import "FIRAuthInteropFake.h"
20-
#import "FIRComponentTestUtilities.h"
21-
#import "FIRDatabaseComponent.h"
22-
2319
@interface FIRFakeOptions: NSObject
2420
@property(nonatomic, readonly, copy) NSString *databaseURL;
25-
- (instancetype)initWithURL:(NSString *)url;
21+
- (instancetype) initWithURL:(NSString *)url;
2622
@end
2723

2824
@implementation FIRFakeOptions
29-
- (instancetype)initWithURL:(NSString *)url {
30-
self = [super init];
31-
if (self) {
32-
_databaseURL = url;
33-
}
34-
return self;
25+
- (instancetype) initWithURL:(NSString *)url {
26+
self = [super init];
27+
if (self) {
28+
self->_databaseURL = url;
29+
}
30+
return self;
3531
}
3632
@end
3733

38-
@interface FIRDatabaseComponent (Internal)
39-
- (instancetype)initWithApp:(FIRApp *)app;
40-
@end
41-
4234
@implementation FIRFakeApp
4335

44-
- (instancetype)initWithName:(NSString *)name URL:(NSString *)url {
45-
self = [super init];
46-
if (self) {
47-
_name = name;
48-
_options = [[FIRFakeOptions alloc] initWithURL:url];
49-
_Nullable id (^authBlock)(FIRComponentContainer *, BOOL *) =
50-
^(FIRComponentContainer *container, BOOL *isCacheable) {
51-
return [[FIRAuthInteropFake alloc] initWithToken:nil userID:nil error:nil];
52-
};
53-
FIRComponentCreationBlock databaseBlock =
54-
^id _Nullable(FIRComponentContainer *container, BOOL *isCacheable) {
55-
return [[FIRDatabaseComponent alloc] initWithApp:container.app];
56-
};
57-
NSDictionary<NSString *, FIRComponentCreationBlock> *components =
58-
@{NSStringFromProtocol(@protocol(FIRAuthInterop)) : authBlock,
59-
NSStringFromProtocol(@protocol(FIRDatabaseProvider)) : databaseBlock};
60-
_container = [[FIRComponentContainer alloc] initWithApp:(FIRApp *)self components:components];
61-
}
62-
return self;
36+
- (instancetype) initWithName:(NSString *)name URL:(NSString *)url {
37+
self = [super init];
38+
if (self) {
39+
self->_name = name;
40+
self->_options = [[FIRFakeOptions alloc] initWithURL:url];
41+
}
42+
return self;
43+
}
44+
45+
- (void)getTokenForcingRefresh:(BOOL)forceRefresh withCallback:(void (^)(NSString *_Nullable token, NSError *_Nullable error))callback {
46+
callback(nil, nil);
6347
}
6448
@end

Example/Database/Tests/Helpers/FTestHelpers.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
#define PATH(__path) [FPath pathWithString:(__path)]
2929

3030
@interface FTestHelpers : XCTestCase
31-
+ (FIRDatabaseConfig *) defaultConfig;
32-
+ (FIRDatabaseConfig *) configForName:(NSString *)name;
3331
+ (FIRDatabaseReference *) getRandomNode;
3432
+ (FIRDatabaseReference *) getRandomNodeWithoutPersistence;
3533
+ (FTupleFirebase *) getRandomNodePair;

Example/Database/Tests/Helpers/FTestHelpers.m

Lines changed: 79 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -15,141 +15,118 @@
1515
*/
1616

1717
#import "FTestHelpers.h"
18-
19-
#import <FirebaseAuthInterop/FIRAuthInterop.h>
20-
#import <FirebaseCore/FIRAppInternal.h>
21-
#import <FirebaseCore/FIRComponent.h>
22-
#import <FirebaseCore/FIRComponentContainer.h>
23-
#import <FirebaseCore/FIROptions.h>
24-
2518
#import "FConstants.h"
26-
#import "FIRAuthInteropFake.h"
19+
#import <FirebaseCore/FIRApp.h>
20+
#import <FirebaseCore/FIROptions.h>
2721
#import "FIRDatabaseConfig_Private.h"
2822
#import "FTestAuthTokenGenerator.h"
2923

3024
@implementation FTestHelpers
3125

32-
+ (NSTimeInterval)waitUntil:(BOOL (^)())predicate timeout:(NSTimeInterval)seconds {
33-
NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
34-
NSDate *timeoutDate = [NSDate dateWithTimeIntervalSinceNow:seconds];
35-
NSTimeInterval timeoutTime = [timeoutDate timeIntervalSinceReferenceDate];
36-
NSTimeInterval currentTime;
37-
38-
for (currentTime = [NSDate timeIntervalSinceReferenceDate];
39-
!predicate() && currentTime < timeoutTime;
40-
currentTime = [NSDate timeIntervalSinceReferenceDate]) {
41-
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
42-
beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
43-
}
26+
+ (NSTimeInterval) waitUntil:(BOOL (^)())predicate timeout:(NSTimeInterval)seconds {
27+
NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
28+
NSDate *timeoutDate = [NSDate dateWithTimeIntervalSinceNow:seconds];
29+
NSTimeInterval timeoutTime = [timeoutDate timeIntervalSinceReferenceDate];
30+
NSTimeInterval currentTime;
4431

45-
NSTimeInterval finish = [NSDate timeIntervalSinceReferenceDate];
32+
for (currentTime = [NSDate timeIntervalSinceReferenceDate];
33+
!predicate() && currentTime < timeoutTime;
34+
currentTime = [NSDate timeIntervalSinceReferenceDate]) {
35+
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
36+
}
4637

47-
NSAssert(currentTime <= timeoutTime, @"Timed out");
38+
NSTimeInterval finish = [NSDate timeIntervalSinceReferenceDate];
4839

49-
return (finish - start);
50-
}
40+
NSAssert(currentTime <= timeoutTime, @"Timed out");
5141

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

56-
+ (FIRDatabaseConfig *)configForName:(NSString *)name {
57-
id<FIRAuthInterop> auth = [[FIRAuthInteropFake alloc] initWithToken:nil userID:nil error:nil];
58-
id<FAuthTokenProvider> authTokenProvider = [FAuthTokenProvider authTokenProviderWithAuth:auth];
59-
return [[FIRDatabaseConfig alloc] initWithSessionIdentifier:name
60-
authTokenProvider:authTokenProvider];
61-
}
45+
+ (NSArray*) getRandomNodes:(int)num persistence:(BOOL)persistence {
46+
static dispatch_once_t pred = 0;
47+
static NSMutableArray *persistenceRefs = nil;
48+
static NSMutableArray *noPersistenceRefs = nil;
49+
dispatch_once(&pred, ^{
50+
persistenceRefs = [[NSMutableArray alloc] init];
51+
noPersistenceRefs = [[NSMutableArray alloc] init];
52+
// Uncomment the following line to run tests against a background thread
53+
//[Firebase setDispatchQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
54+
});
55+
56+
NSMutableArray *refs = (persistence) ? persistenceRefs : noPersistenceRefs;
57+
58+
id<FAuthTokenProvider> authTokenProvider = [FAuthTokenProvider authTokenProviderForApp:[FIRApp defaultApp]];
59+
60+
while (num > refs.count) {
61+
NSString *sessionIdentifier = [NSString stringWithFormat:@"test-config-%@persistence-%lu", (persistence) ? @"" : @"no-", refs.count];
62+
FIRDatabaseConfig *config = [[FIRDatabaseConfig alloc] initWithSessionIdentifier:sessionIdentifier authTokenProvider:authTokenProvider];
63+
config.persistenceEnabled = persistence;
64+
FIRDatabaseReference * ref = [[FIRDatabaseReference alloc] initWithConfig:config];
65+
[refs addObject:ref];
66+
}
6267

63-
+ (NSArray *)getRandomNodes:(int)num persistence:(BOOL)persistence {
64-
static dispatch_once_t pred = 0;
65-
static NSMutableArray *persistenceRefs = nil;
66-
static NSMutableArray *noPersistenceRefs = nil;
67-
dispatch_once(&pred, ^{
68-
persistenceRefs = [[NSMutableArray alloc] init];
69-
noPersistenceRefs = [[NSMutableArray alloc] init];
70-
// Uncomment the following line to run tests against a background thread
71-
//[Firebase setDispatchQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)];
72-
});
73-
74-
NSMutableArray *refs = (persistence) ? persistenceRefs : noPersistenceRefs;
75-
76-
id<FIRAuthInterop> auth = [[FIRAuthInteropFake alloc] initWithToken:nil userID:nil error:nil];
77-
id<FAuthTokenProvider> authTokenProvider = [FAuthTokenProvider authTokenProviderWithAuth:auth];
78-
79-
while (num > refs.count) {
80-
NSString *sessionIdentifier =
81-
[NSString stringWithFormat:@"test-config-%@persistence-%lu", (persistence) ? @"" : @"no-",
82-
refs.count];
83-
FIRDatabaseConfig *config =
84-
[[FIRDatabaseConfig alloc] initWithSessionIdentifier:sessionIdentifier
85-
authTokenProvider:authTokenProvider];
86-
config.persistenceEnabled = persistence;
87-
FIRDatabaseReference *ref = [[FIRDatabaseReference alloc] initWithConfig:config];
88-
[refs addObject:ref];
89-
}
90-
91-
NSMutableArray *results = [[NSMutableArray alloc] init];
92-
NSString *name = nil;
93-
for (int i = 0; i < num; ++i) {
94-
FIRDatabaseReference *ref = [refs objectAtIndex:i];
95-
if (!name) {
96-
name = [ref childByAutoId].key;
68+
NSMutableArray* results = [[NSMutableArray alloc] init];
69+
NSString* name = nil;
70+
for (int i = 0; i < num; ++i) {
71+
FIRDatabaseReference * ref = [refs objectAtIndex:i];
72+
if (!name) {
73+
name = [ref childByAutoId].key;
74+
}
75+
[results addObject:[ref child:name]];
9776
}
98-
[results addObject:[ref child:name]];
99-
}
100-
return results;
77+
return results;
10178
}
10279

10380
// Helpers
104-
+ (FIRDatabaseReference *)getRandomNode {
105-
NSArray *refs = [self getRandomNodes:1 persistence:YES];
106-
return [refs objectAtIndex:0];
81+
+ (FIRDatabaseReference *) getRandomNode {
82+
NSArray* refs = [self getRandomNodes:1 persistence:YES];
83+
return [refs objectAtIndex:0];
10784
}
10885

109-
+ (FIRDatabaseReference *)getRandomNodeWithoutPersistence {
110-
NSArray *refs = [self getRandomNodes:1 persistence:NO];
111-
return refs[0];
86+
+ (FIRDatabaseReference *) getRandomNodeWithoutPersistence {
87+
NSArray* refs = [self getRandomNodes:1 persistence:NO];
88+
return refs[0];
11289
}
11390

114-
+ (FTupleFirebase *)getRandomNodePair {
115-
NSArray *refs = [self getRandomNodes:2 persistence:YES];
91+
+ (FTupleFirebase *) getRandomNodePair {
92+
NSArray* refs = [self getRandomNodes:2 persistence:YES];
11693

117-
FTupleFirebase *tuple = [[FTupleFirebase alloc] init];
118-
tuple.one = [refs objectAtIndex:0];
119-
tuple.two = [refs objectAtIndex:1];
94+
FTupleFirebase* tuple = [[FTupleFirebase alloc] init];
95+
tuple.one = [refs objectAtIndex:0];
96+
tuple.two = [refs objectAtIndex:1];
12097

121-
return tuple;
98+
return tuple;
12299
}
123100

124-
+ (FTupleFirebase *)getRandomNodePairWithoutPersistence {
125-
NSArray *refs = [self getRandomNodes:2 persistence:NO];
101+
+ (FTupleFirebase *) getRandomNodePairWithoutPersistence {
102+
NSArray* refs = [self getRandomNodes:2 persistence:NO];
126103

127-
FTupleFirebase *tuple = [[FTupleFirebase alloc] init];
128-
tuple.one = refs[0];
129-
tuple.two = refs[1];
104+
FTupleFirebase* tuple = [[FTupleFirebase alloc] init];
105+
tuple.one = refs[0];
106+
tuple.two = refs[1];
130107

131-
return tuple;
108+
return tuple;
132109
}
133110

134-
+ (FTupleFirebase *)getRandomNodeTriple {
135-
NSArray *refs = [self getRandomNodes:3 persistence:YES];
136-
FTupleFirebase *triple = [[FTupleFirebase alloc] init];
137-
triple.one = [refs objectAtIndex:0];
138-
triple.two = [refs objectAtIndex:1];
139-
triple.three = [refs objectAtIndex:2];
111+
+ (FTupleFirebase *) getRandomNodeTriple {
112+
NSArray* refs = [self getRandomNodes:3 persistence:YES];
113+
FTupleFirebase* triple = [[FTupleFirebase alloc] init];
114+
triple.one = [refs objectAtIndex:0];
115+
triple.two = [refs objectAtIndex:1];
116+
triple.three = [refs objectAtIndex:2];
140117

141-
return triple;
118+
return triple;
142119
}
143120

144121
+ (id<FNode>)leafNodeOfSize:(NSUInteger)size {
145-
NSMutableString *string = [NSMutableString string];
146-
NSString *pattern = @"abdefghijklmopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
147-
for (NSUInteger i = 0; i < size - pattern.length; i = i + pattern.length) {
148-
[string appendString:pattern];
149-
}
150-
NSUInteger remainingLength = size - string.length;
151-
[string appendString:[pattern substringToIndex:remainingLength]];
152-
return [FSnapshotUtilities nodeFrom:string];
122+
NSMutableString *string = [NSMutableString string];
123+
NSString *pattern = @"abdefghijklmopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
124+
for (NSUInteger i = 0; i < size - pattern.length; i = i + pattern.length) {
125+
[string appendString:pattern];
126+
}
127+
NSUInteger remainingLength = size - string.length;
128+
[string appendString:[pattern substringToIndex:remainingLength]];
129+
return [FSnapshotUtilities nodeFrom:string];
153130
}
154131

155132
@end

Example/Database/Tests/Integration/FData.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2529,7 +2529,7 @@ - (void) testUpdateAfterChildSet {
25292529

25302530
- (void) testDeltaSyncNoDataUpdatesAfterReconnect {
25312531
FIRDatabaseReference *ref = [FTestHelpers getRandomNode];
2532-
FIRDatabaseConfig *cfg = [FTestHelpers configForName:@"test-config"];
2532+
FIRDatabaseConfig *cfg = [FIRDatabaseConfig configForName:@"test-config"];
25332533
FIRDatabaseReference * ref2 = [[[FIRDatabaseReference alloc] initWithConfig:cfg] child:ref.key];
25342534
__block id data = @{ @"a": @1, @"b": @2, @"c": @{ @".priority": @3, @".value": @3}, @"d": @4 };
25352535
[self waitForCompletionOf:ref setValue:data];

Example/Database/Tests/Integration/FDotInfo.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ - (void) testCanWatchInfoConnected {
5151
}
5252

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

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

8484
// make sure childByAutoId works
@@ -103,8 +103,8 @@ - (void) testInfoServerTimeOffset {
103103
}
104104

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

109109
FIRDatabaseReference * ref = [[FIRDatabaseReference alloc] initWithConfig:cfg];
110110
FIRDatabaseReference * refAlt = [[FIRDatabaseReference alloc] initWithConfig:altCfg];

0 commit comments

Comments
 (0)