Skip to content

Commit 43d15ec

Browse files
author
Greg Soltis
authored
Start restarting persistence in spec tests (#1713)
* Update json files * Start restarting persistence in spec tests
1 parent e70eebd commit 43d15ec

10 files changed

+117
-99
lines changed

Firestore/Example/Tests/SpecTests/FSTLevelDBSpecTests.mm

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
#import "Firestore/Example/Tests/SpecTests/FSTSpecTests.h"
1818

1919
#import "Firestore/Source/Local/FSTLevelDB.h"
20+
#include "Firestore/core/src/firebase/firestore/util/path.h"
2021

2122
#import "Firestore/Example/Tests/Local/FSTPersistenceTestHelpers.h"
2223
#import "Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h"
2324

25+
using firebase::firestore::util::Path;
26+
2427
NS_ASSUME_NONNULL_BEGIN
2528

2629
/**
@@ -31,15 +34,23 @@
3134
@interface FSTLevelDBSpecTests : FSTSpecTests
3235
@end
3336

34-
@implementation FSTLevelDBSpecTests
37+
@implementation FSTLevelDBSpecTests {
38+
Path _levelDbDir;
39+
}
40+
41+
- (void)setUpForSpecWithConfig:(NSDictionary *)config {
42+
// Getting a new directory will ensure that it is empty.
43+
_levelDbDir = [FSTPersistenceTestHelpers levelDBDir];
44+
[super setUpForSpecWithConfig:config];
45+
}
3546

3647
/** Overrides -[FSTSpecTests persistence] */
3748
- (id<FSTPersistence>)persistenceWithGCEnabled:(__unused BOOL)GCEnabled {
38-
return [FSTPersistenceTestHelpers levelDBPersistence];
49+
return [FSTPersistenceTestHelpers levelDBPersistenceWithDir:_levelDbDir];
3950
}
4051

4152
- (BOOL)shouldRunWithTags:(NSArray<NSString *> *)tags {
42-
if ([tags containsObject:kNoLRUTag]) {
53+
if ([tags containsObject:kEagerGC]) {
4354
return NO;
4455
}
4556

Firestore/Example/Tests/SpecTests/FSTMemorySpecTests.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ @implementation FSTMemorySpecTests
4242
}
4343
}
4444

45+
- (BOOL)shouldRunWithTags:(NSArray<NSString *> *)tags {
46+
if ([tags containsObject:kDurablePersistence]) {
47+
return NO;
48+
}
49+
50+
return [super shouldRunWithTags:tags];
51+
}
52+
4553
@end
4654

4755
NS_ASSUME_NONNULL_END

Firestore/Example/Tests/SpecTests/FSTSpecTests.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
NS_ASSUME_NONNULL_BEGIN
2323

24-
extern NSString *const kNoLRUTag;
24+
extern NSString *const kEagerGC;
25+
extern NSString *const kDurablePersistence;
2526

2627
/**
2728
* FSTSpecTests run a set of portable event specifications from JSON spec files against a
@@ -43,6 +44,9 @@ extern NSString *const kNoLRUTag;
4344
/** Based on its tags, determine whether the test case should run. */
4445
- (BOOL)shouldRunWithTags:(NSArray<NSString *> *)tags;
4546

47+
/** Do any necessary setup for a single spec test */
48+
- (void)setUpForSpecWithConfig:(NSDictionary *)config;
49+
4650
@end
4751

4852
NS_ASSUME_NONNULL_END

Firestore/Example/Tests/SpecTests/FSTSpecTests.mm

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@
7676
// if `kRunBenchmarkTests` is set to 'YES'.
7777
static NSString *const kBenchmarkTag = @"benchmark";
7878

79-
NSString *const kNoLRUTag = @"no-lru";
79+
NSString *const kEagerGC = @"eager-gc";
80+
81+
NSString *const kDurablePersistence = @"durable-persistence";
8082

8183
static NSString *Describe(NSData *data) {
8284
return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
@@ -85,11 +87,11 @@
8587
@interface FSTSpecTests ()
8688
@property(nonatomic, strong) FSTSyncEngineTestDriver *driver;
8789

88-
// Some config info for the currently running spec; used when restarting the driver (for doRestart).
89-
@property(nonatomic, strong) id<FSTPersistence> driverPersistence;
9090
@end
9191

92-
@implementation FSTSpecTests
92+
@implementation FSTSpecTests {
93+
BOOL _gcEnabled;
94+
}
9395

9496
- (id<FSTPersistence>)persistenceWithGCEnabled:(BOOL)GCEnabled {
9597
@throw FSTAbstractMethodException(); // NOLINT
@@ -107,20 +109,20 @@ - (BOOL)shouldRunWithTags:(NSArray<NSString *> *)tags {
107109
}
108110

109111
- (void)setUpForSpecWithConfig:(NSDictionary *)config {
110-
// Store persistence / GCEnabled so we can re-use it in doRestart.
112+
// Store GCEnabled so we can re-use it in doRestart.
111113
NSNumber *GCEnabled = config[@"useGarbageCollection"];
114+
_gcEnabled = [GCEnabled boolValue];
112115
NSNumber *numClients = config[@"numClients"];
113116
if (numClients) {
114117
XCTAssertEqualObjects(numClients, @1, @"The iOS client does not support multi-client tests");
115118
}
116-
self.driverPersistence = [self persistenceWithGCEnabled:[GCEnabled boolValue]];
117-
self.driver = [[FSTSyncEngineTestDriver alloc] initWithPersistence:self.driverPersistence];
119+
id<FSTPersistence> persistence = [self persistenceWithGCEnabled:_gcEnabled];
120+
self.driver = [[FSTSyncEngineTestDriver alloc] initWithPersistence:persistence];
118121
[self.driver start];
119122
}
120123

121124
- (void)tearDownForSpec {
122125
[self.driver shutdown];
123-
[self.driverPersistence shutdown];
124126
}
125127

126128
/**
@@ -410,13 +412,8 @@ - (void)doRestart {
410412

411413
[self.driver shutdown];
412414

413-
// NOTE: We intentionally don't shutdown / re-create driverPersistence, since we want to
414-
// preserve the persisted state. This is a bit of a cheat since it means we're not exercising
415-
// the initialization / start logic that would normally be hit, but simplifies the plumbing and
416-
// allows us to run these tests against FSTMemoryPersistence as well (there would be no way to
417-
// re-create FSTMemoryPersistence without losing all persisted state).
418-
419-
self.driver = [[FSTSyncEngineTestDriver alloc] initWithPersistence:self.driverPersistence
415+
id<FSTPersistence> persistence = [self persistenceWithGCEnabled:_gcEnabled];
416+
self.driver = [[FSTSyncEngineTestDriver alloc] initWithPersistence:persistence
420417
initialUser:currentUser
421418
outstandingWrites:outstandingWrites];
422419
[self.driver start];

Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.mm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ @interface FSTSyncEngineTestDriver ()
7777
@property(nonatomic, strong, readonly) FSTLocalStore *localStore;
7878
@property(nonatomic, strong, readonly) FSTSyncEngine *syncEngine;
7979
@property(nonatomic, strong, readonly) FSTDispatchQueue *dispatchQueue;
80+
@property(nonatomic, strong, readonly) id<FSTPersistence> persistence;
8081

8182
#pragma mark - Data structures for holding events sent by the watch stream.
8283

@@ -129,6 +130,7 @@ - (instancetype)initWithPersistence:(id<FSTPersistence>)persistence
129130
dispatch_queue_t queue =
130131
dispatch_queue_create("sync_engine_test_driver", DISPATCH_QUEUE_SERIAL);
131132
_dispatchQueue = [FSTDispatchQueue queueWith:queue];
133+
_persistence = persistence;
132134
_localStore = [[FSTLocalStore alloc] initWithPersistence:persistence initialUser:initialUser];
133135
_datastore = [[FSTMockDatastore alloc] initWithDatabaseInfo:&_databaseInfo
134136
workerDispatchQueue:_dispatchQueue
@@ -203,6 +205,7 @@ - (void)validateUsage {
203205
- (void)shutdown {
204206
[self.dispatchQueue dispatchSync:^{
205207
[self.remoteStore shutdown];
208+
[self.persistence shutdown];
206209
}];
207210
}
208211

Firestore/Example/Tests/SpecTests/json/listen_spec_test.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"describeName": "Listens:",
44
"itName": "Contents of query are cleared when listen is removed.",
55
"tags": [
6-
"no-lru"
6+
"eager-gc"
77
],
88
"comment": "Explicitly tests eager GC behavior",
99
"config": {
@@ -1287,7 +1287,9 @@
12871287
"Will gracefully handle watch stream reverting snapshots (with restart)": {
12881288
"describeName": "Listens:",
12891289
"itName": "Will gracefully handle watch stream reverting snapshots (with restart)",
1290-
"tags": [],
1290+
"tags": [
1291+
"durable-persistence"
1292+
],
12911293
"config": {
12921294
"useGarbageCollection": false,
12931295
"numClients": 1
@@ -4248,7 +4250,9 @@
42484250
"Omits global resume tokens for a short while": {
42494251
"describeName": "Listens:",
42504252
"itName": "Omits global resume tokens for a short while",
4251-
"tags": [],
4253+
"tags": [
4254+
"durable-persistence"
4255+
],
42524256
"config": {
42534257
"useGarbageCollection": false,
42544258
"numClients": 1
@@ -4423,7 +4427,9 @@
44234427
"Persists global resume tokens if the snapshot is old enough": {
44244428
"describeName": "Listens:",
44254429
"itName": "Persists global resume tokens if the snapshot is old enough",
4426-
"tags": [],
4430+
"tags": [
4431+
"durable-persistence"
4432+
],
44274433
"config": {
44284434
"useGarbageCollection": false,
44294435
"numClients": 1

Firestore/Example/Tests/SpecTests/json/offline_spec_test.json

Lines changed: 23 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
"Empty queries are resolved if client goes offline": {
33
"describeName": "Offline:",
44
"itName": "Empty queries are resolved if client goes offline",
5-
"tags": [],
5+
"tags": [
6+
"no-android",
7+
"no-ios"
8+
],
69
"config": {
710
"useGarbageCollection": true,
811
"numClients": 1
@@ -30,15 +33,6 @@
3033
}
3134
}
3235
},
33-
{
34-
"watchStreamClose": {
35-
"error": {
36-
"code": 14,
37-
"message": "Simulated Backend Error"
38-
},
39-
"runBackoffTimer": true
40-
}
41-
},
4236
{
4337
"watchStreamClose": {
4438
"error": {
@@ -83,7 +77,10 @@
8377
"A successful message delays offline status": {
8478
"describeName": "Offline:",
8579
"itName": "A successful message delays offline status",
86-
"tags": [],
80+
"tags": [
81+
"no-android",
82+
"no-ios"
83+
],
8784
"config": {
8885
"useGarbageCollection": true,
8986
"numClients": 1
@@ -125,15 +122,6 @@
125122
"runBackoffTimer": true
126123
}
127124
},
128-
{
129-
"watchStreamClose": {
130-
"error": {
131-
"code": 14,
132-
"message": "Simulated Backend Error"
133-
},
134-
"runBackoffTimer": true
135-
}
136-
},
137125
{
138126
"watchStreamClose": {
139127
"error": {
@@ -179,7 +167,9 @@
179167
"describeName": "Offline:",
180168
"itName": "Removing all listeners delays \"Offline\" status on next listen",
181169
"tags": [
182-
"no-lru"
170+
"eager-gc",
171+
"no-android",
172+
"no-ios"
183173
],
184174
"comment": "Marked as no-lru because when a listen is re-added, it gets a new target id rather than reusing one",
185175
"config": {
@@ -209,15 +199,6 @@
209199
}
210200
}
211201
},
212-
{
213-
"watchStreamClose": {
214-
"error": {
215-
"code": 14,
216-
"message": "Simulated Backend Error"
217-
},
218-
"runBackoffTimer": true
219-
}
220-
},
221202
{
222203
"watchStreamClose": {
223204
"error": {
@@ -283,15 +264,6 @@
283264
}
284265
}
285266
},
286-
{
287-
"watchStreamClose": {
288-
"error": {
289-
"code": 14,
290-
"message": "Simulated Backend Error"
291-
},
292-
"runBackoffTimer": true
293-
}
294-
},
295267
{
296268
"watchStreamClose": {
297269
"error": {
@@ -318,7 +290,10 @@
318290
"Queries revert to fromCache=true when offline.": {
319291
"describeName": "Offline:",
320292
"itName": "Queries revert to fromCache=true when offline.",
321-
"tags": [],
293+
"tags": [
294+
"no-android",
295+
"no-ios"
296+
],
322297
"config": {
323298
"useGarbageCollection": true,
324299
"numClients": 1
@@ -422,15 +397,6 @@
422397
}
423398
}
424399
},
425-
{
426-
"watchStreamClose": {
427-
"error": {
428-
"code": 14,
429-
"message": "Simulated Backend Error"
430-
},
431-
"runBackoffTimer": true
432-
}
433-
},
434400
{
435401
"watchStreamClose": {
436402
"error": {
@@ -495,7 +461,10 @@
495461
"Queries with limbo documents handle going offline.": {
496462
"describeName": "Offline:",
497463
"itName": "Queries with limbo documents handle going offline.",
498-
"tags": [],
464+
"tags": [
465+
"no-android",
466+
"no-ios"
467+
],
499468
"config": {
500469
"useGarbageCollection": true,
501470
"numClients": 1
@@ -669,15 +638,6 @@
669638
"runBackoffTimer": true
670639
}
671640
},
672-
{
673-
"watchStreamClose": {
674-
"error": {
675-
"code": 14,
676-
"message": "Simulated Backend Error"
677-
},
678-
"runBackoffTimer": true
679-
}
680-
},
681641
{
682642
"watchAck": [
683643
2
@@ -929,7 +889,10 @@
929889
"New queries return immediately with fromCache=true when offline due to stream failures.": {
930890
"describeName": "Offline:",
931891
"itName": "New queries return immediately with fromCache=true when offline due to stream failures.",
932-
"tags": [],
892+
"tags": [
893+
"no-android",
894+
"no-ios"
895+
],
933896
"config": {
934897
"useGarbageCollection": true,
935898
"numClients": 1
@@ -957,15 +920,6 @@
957920
}
958921
}
959922
},
960-
{
961-
"watchStreamClose": {
962-
"error": {
963-
"code": 14,
964-
"message": "Simulated Backend Error"
965-
},
966-
"runBackoffTimer": true
967-
}
968-
},
969923
{
970924
"watchStreamClose": {
971925
"error": {

0 commit comments

Comments
 (0)