Skip to content

Commit b05e9eb

Browse files
authored
Update spec tests from changes in the firebase-js-sdk respository (#5278)
1 parent 4d86017 commit b05e9eb

16 files changed

+197867
-184485
lines changed

Firestore/Example/Tests/SpecTests/FSTSpecTests.mm

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#import <FirebaseFirestore/FIRFirestoreErrors.h>
2020

21+
#include <algorithm>
2122
#include <map>
2223
#include <memory>
2324
#include <string>
@@ -92,6 +93,7 @@
9293
using firebase::firestore::remote::ExistenceFilterWatchChange;
9394
using firebase::firestore::remote::WatchTargetChange;
9495
using firebase::firestore::remote::WatchTargetChangeState;
96+
using firebase::firestore::util::MakeNSString;
9597
using firebase::firestore::util::MakeString;
9698
using firebase::firestore::util::Path;
9799
using firebase::firestore::util::Status;
@@ -150,6 +152,26 @@ ByteString MakeResumeToken(NSString *specString) {
150152
return MakeByteString([specString dataUsingEncoding:NSUTF8StringEncoding]);
151153
}
152154

155+
NSString *ToDocumentListString(const std::map<DocumentKey, TargetId> &map) {
156+
std::vector<std::string> strings;
157+
strings.reserve(map.size());
158+
for (const auto &kv : map) {
159+
strings.push_back(kv.first.ToString());
160+
}
161+
std::sort(strings.begin(), strings.end());
162+
return MakeNSString(absl::StrJoin(strings, ", "));
163+
}
164+
165+
NSString *ToTargetIdListString(const ActiveTargetMap &map) {
166+
std::vector<model::TargetId> targetIds;
167+
targetIds.reserve(map.size());
168+
for (const auto &kv : map) {
169+
targetIds.push_back(kv.first);
170+
}
171+
std::sort(targetIds.begin(), targetIds.end());
172+
return MakeNSString(absl::StrJoin(targetIds, ", "));
173+
}
174+
153175
} // namespace
154176

155177
@interface FSTSpecTests ()
@@ -661,14 +683,14 @@ - (void)validateExpectedState:(nullable NSDictionary *)expectedState {
661683
XCTAssertEqual([self.driver watchStreamRequestCount],
662684
[expectedState[@"watchStreamRequestCount"] intValue]);
663685
}
664-
if (expectedState[@"limboDocs"]) {
665-
DocumentKeySet expectedLimboDocuments;
666-
NSArray *docNames = expectedState[@"limboDocs"];
686+
if (expectedState[@"activeLimboDocs"]) {
687+
DocumentKeySet expectedActiveLimboDocuments;
688+
NSArray *docNames = expectedState[@"activeLimboDocs"];
667689
for (NSString *name in docNames) {
668-
expectedLimboDocuments = expectedLimboDocuments.insert(FSTTestDocKey(name));
690+
expectedActiveLimboDocuments = expectedActiveLimboDocuments.insert(FSTTestDocKey(name));
669691
}
670692
// Update the expected limbo documents
671-
[self.driver setExpectedLimboDocuments:std::move(expectedLimboDocuments)];
693+
[self.driver setExpectedActiveLimboDocuments:std::move(expectedActiveLimboDocuments)];
672694
}
673695
if (expectedState[@"activeTargets"]) {
674696
__block ActiveTargetMap expectedActiveTargets;
@@ -726,21 +748,23 @@ - (void)validateLimboDocuments {
726748
// Make a copy so it can modified while checking against the expected limbo docs.
727749
std::map<DocumentKey, TargetId> actualLimboDocs = self.driver.currentLimboDocuments;
728750

729-
// Validate that each limbo doc has an expected active target
751+
// Validate that each active limbo doc has an expected active target
730752
for (const auto &kv : actualLimboDocs) {
731753
const auto &expected = [self.driver expectedActiveTargets];
732754
XCTAssertTrue(expected.find(kv.second) != expected.end(),
733-
@"Found limbo doc without an expected active target");
755+
@"Found limbo doc %s, but its target ID %d was not in the "
756+
@"set of expected active target IDs %@",
757+
kv.first.ToString().c_str(), kv.second, ToTargetIdListString(expected));
734758
}
735759

736-
for (const DocumentKey &expectedLimboDoc : self.driver.expectedLimboDocuments) {
760+
for (const DocumentKey &expectedLimboDoc : self.driver.expectedActiveLimboDocuments) {
737761
XCTAssert(actualLimboDocs.find(expectedLimboDoc) != actualLimboDocs.end(),
738762
@"Expected doc to be in limbo, but was not: %s", expectedLimboDoc.ToString().c_str());
739763
actualLimboDocs.erase(expectedLimboDoc);
740764
}
741-
XCTAssertTrue(actualLimboDocs.empty(), "%lu Unexpected docs in limbo, the first one is <%s, %d>",
742-
actualLimboDocs.size(), actualLimboDocs.begin()->first.ToString().c_str(),
743-
actualLimboDocs.begin()->second);
765+
766+
XCTAssertTrue(actualLimboDocs.empty(), @"Unexpected active docs in limbo: %@",
767+
ToDocumentListString(actualLimboDocs));
744768
}
745769

746770
- (void)validateActiveTargets {

Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,11 @@ typedef std::unordered_map<auth::User, NSMutableArray<FSTOutstandingWrite *> *,
292292
/** The current set of documents in limbo. */
293293
- (std::map<model::DocumentKey, model::TargetId>)currentLimboDocuments;
294294

295-
/** The expected set of documents in limbo. */
296-
- (const model::DocumentKeySet &)expectedLimboDocuments;
295+
/** The expected set of documents in limbo with an active target. */
296+
- (const model::DocumentKeySet &)expectedActiveLimboDocuments;
297297

298-
/** Sets the expected set of documents in limbo. */
299-
- (void)setExpectedLimboDocuments:(model::DocumentKeySet)docs;
298+
/** Sets the expected set of documents in limbo with an active target. */
299+
- (void)setExpectedActiveLimboDocuments:(model::DocumentKeySet)docs;
300300

301301
/**
302302
* The writes that have been sent to the FSTSyncEngine via writeUserMutation: but not yet

Firestore/Example/Tests/SpecTests/FSTSyncEngineTestDriver.mm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ @implementation FSTSyncEngineTestDriver {
172172

173173
// ivar is declared as mutable.
174174
std::unordered_map<User, NSMutableArray<FSTOutstandingWrite *> *, HashUser> _outstandingWrites;
175-
DocumentKeySet _expectedLimboDocuments;
175+
DocumentKeySet _expectedActiveLimboDocuments;
176176

177177
/** A dictionary for tracking the listens on queries. */
178178
std::unordered_map<Query, std::shared_ptr<QueryListener>> _queryListeners;
@@ -243,12 +243,12 @@ - (instancetype)initWithPersistence:(std::unique_ptr<Persistence>)persistence
243243
return _outstandingWrites;
244244
}
245245

246-
- (const DocumentKeySet &)expectedLimboDocuments {
247-
return _expectedLimboDocuments;
246+
- (const DocumentKeySet &)expectedActiveLimboDocuments {
247+
return _expectedActiveLimboDocuments;
248248
}
249249

250-
- (void)setExpectedLimboDocuments:(DocumentKeySet)docs {
251-
_expectedLimboDocuments = std::move(docs);
250+
- (void)setExpectedActiveLimboDocuments:(DocumentKeySet)docs {
251+
_expectedActiveLimboDocuments = std::move(docs);
252252
}
253253

254254
- (void)drainQueue {

Firestore/Example/Tests/SpecTests/json/collection_spec_test.json

Lines changed: 62 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,34 @@
22
"Events are raised after watch ack": {
33
"describeName": "Collections:",
44
"itName": "Events are raised after watch ack",
5-
"tags": [],
5+
"tags": [
6+
],
67
"config": {
7-
"useGarbageCollection": true,
8-
"numClients": 1
8+
"numClients": 1,
9+
"useGarbageCollection": true
910
},
1011
"steps": [
1112
{
1213
"userListen": [
1314
2,
1415
{
15-
"path": "collection",
16-
"filters": [],
17-
"orderBys": []
16+
"filters": [
17+
],
18+
"orderBys": [
19+
],
20+
"path": "collection"
1821
}
1922
],
2023
"expectedState": {
2124
"activeTargets": {
2225
"2": {
2326
"queries": [
2427
{
25-
"path": "collection",
26-
"filters": [],
27-
"orderBys": []
28+
"filters": [
29+
],
30+
"orderBys": [
31+
],
32+
"path": "collection"
2833
}
2934
],
3035
"resumeToken": ""
@@ -42,14 +47,14 @@
4247
"docs": [
4348
{
4449
"key": "collection/key",
45-
"version": 1000,
50+
"options": {
51+
"hasCommittedMutations": false,
52+
"hasLocalMutations": false
53+
},
4654
"value": {
4755
"foo": "bar"
4856
},
49-
"options": {
50-
"hasLocalMutations": false,
51-
"hasCommittedMutations": false
52-
}
57+
"version": 1000
5358
}
5459
],
5560
"targets": [
@@ -67,32 +72,35 @@
6772
},
6873
{
6974
"watchSnapshot": {
70-
"version": 1001,
71-
"targetIds": []
75+
"targetIds": [
76+
],
77+
"version": 1001
7278
},
7379
"expectedSnapshotEvents": [
7480
{
75-
"query": {
76-
"path": "collection",
77-
"filters": [],
78-
"orderBys": []
79-
},
8081
"added": [
8182
{
8283
"key": "collection/key",
83-
"version": 1000,
84+
"options": {
85+
"hasCommittedMutations": false,
86+
"hasLocalMutations": false
87+
},
8488
"value": {
8589
"foo": "bar"
8690
},
87-
"options": {
88-
"hasLocalMutations": false,
89-
"hasCommittedMutations": false
90-
}
91+
"version": 1000
9192
}
9293
],
9394
"errorCode": 0,
9495
"fromCache": false,
95-
"hasPendingWrites": false
96+
"hasPendingWrites": false,
97+
"query": {
98+
"filters": [
99+
],
100+
"orderBys": [
101+
],
102+
"path": "collection"
103+
}
96104
}
97105
]
98106
}
@@ -101,29 +109,34 @@
101109
"Events are raised for local sets before watch ack": {
102110
"describeName": "Collections:",
103111
"itName": "Events are raised for local sets before watch ack",
104-
"tags": [],
112+
"tags": [
113+
],
105114
"config": {
106-
"useGarbageCollection": true,
107-
"numClients": 1
115+
"numClients": 1,
116+
"useGarbageCollection": true
108117
},
109118
"steps": [
110119
{
111120
"userListen": [
112121
2,
113122
{
114-
"path": "collection",
115-
"filters": [],
116-
"orderBys": []
123+
"filters": [
124+
],
125+
"orderBys": [
126+
],
127+
"path": "collection"
117128
}
118129
],
119130
"expectedState": {
120131
"activeTargets": {
121132
"2": {
122133
"queries": [
123134
{
124-
"path": "collection",
125-
"filters": [],
126-
"orderBys": []
135+
"filters": [
136+
],
137+
"orderBys": [
138+
],
139+
"path": "collection"
127140
}
128141
],
129142
"resumeToken": ""
@@ -140,27 +153,29 @@
140153
],
141154
"expectedSnapshotEvents": [
142155
{
143-
"query": {
144-
"path": "collection",
145-
"filters": [],
146-
"orderBys": []
147-
},
148156
"added": [
149157
{
150158
"key": "collection/key",
151-
"version": 0,
159+
"options": {
160+
"hasCommittedMutations": false,
161+
"hasLocalMutations": true
162+
},
152163
"value": {
153164
"foo": "bar"
154165
},
155-
"options": {
156-
"hasLocalMutations": true,
157-
"hasCommittedMutations": false
158-
}
166+
"version": 0
159167
}
160168
],
161169
"errorCode": 0,
162170
"fromCache": true,
163-
"hasPendingWrites": true
171+
"hasPendingWrites": true,
172+
"query": {
173+
"filters": [
174+
],
175+
"orderBys": [
176+
],
177+
"path": "collection"
178+
}
164179
}
165180
]
166181
}

0 commit comments

Comments
 (0)