FSTLocalStoreTests.mm 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "Firestore/Source/Local/FSTLocalStore.h"
  17. #import <FirebaseFirestore/FIRTimestamp.h>
  18. #import <XCTest/XCTest.h>
  19. #import "Firestore/Source/Core/FSTQuery.h"
  20. #import "Firestore/Source/Local/FSTLocalWriteResult.h"
  21. #import "Firestore/Source/Local/FSTPersistence.h"
  22. #import "Firestore/Source/Local/FSTQueryCache.h"
  23. #import "Firestore/Source/Local/FSTQueryData.h"
  24. #import "Firestore/Source/Model/FSTDocument.h"
  25. #import "Firestore/Source/Model/FSTDocumentKey.h"
  26. #import "Firestore/Source/Model/FSTDocumentSet.h"
  27. #import "Firestore/Source/Model/FSTMutation.h"
  28. #import "Firestore/Source/Model/FSTMutationBatch.h"
  29. #import "Firestore/Source/Remote/FSTRemoteEvent.h"
  30. #import "Firestore/Source/Remote/FSTWatchChange.h"
  31. #import "Firestore/Source/Util/FSTClasses.h"
  32. #import "Firestore/Example/Tests/Local/FSTLocalStoreTests.h"
  33. #import "Firestore/Example/Tests/Remote/FSTWatchChange+Testing.h"
  34. #import "Firestore/Example/Tests/Util/FSTHelpers.h"
  35. #import "Firestore/third_party/Immutable/Tests/FSTImmutableSortedDictionary+Testing.h"
  36. #import "Firestore/third_party/Immutable/Tests/FSTImmutableSortedSet+Testing.h"
  37. #include "Firestore/core/src/firebase/firestore/auth/user.h"
  38. #include "Firestore/core/test/firebase/firestore/testutil/testutil.h"
  39. namespace testutil = firebase::firestore::testutil;
  40. using firebase::firestore::auth::User;
  41. using firebase::firestore::model::DocumentKeySet;
  42. using firebase::firestore::model::ListenSequenceNumber;
  43. using firebase::firestore::model::SnapshotVersion;
  44. using firebase::firestore::model::TargetId;
  45. NS_ASSUME_NONNULL_BEGIN
  46. @interface FSTLocalStoreTests ()
  47. @property(nonatomic, strong, readwrite) id<FSTPersistence> localStorePersistence;
  48. @property(nonatomic, strong, readwrite) FSTLocalStore *localStore;
  49. @property(nonatomic, strong, readonly) NSMutableArray<FSTMutationBatch *> *batches;
  50. @property(nonatomic, strong, readwrite, nullable) FSTMaybeDocumentDictionary *lastChanges;
  51. @property(nonatomic, assign, readwrite) TargetId lastTargetID;
  52. @end
  53. @implementation FSTLocalStoreTests
  54. - (void)setUp {
  55. [super setUp];
  56. if ([self isTestBaseClass]) {
  57. return;
  58. }
  59. id<FSTPersistence> persistence = [self persistence];
  60. self.localStorePersistence = persistence;
  61. self.localStore =
  62. [[FSTLocalStore alloc] initWithPersistence:persistence initialUser:User::Unauthenticated()];
  63. [self.localStore start];
  64. _batches = [NSMutableArray array];
  65. _lastChanges = nil;
  66. _lastTargetID = 0;
  67. }
  68. - (void)tearDown {
  69. [self.localStorePersistence shutdown];
  70. [super tearDown];
  71. }
  72. - (id<FSTPersistence>)persistence {
  73. @throw FSTAbstractMethodException(); // NOLINT
  74. }
  75. - (BOOL)gcIsEager {
  76. @throw FSTAbstractMethodException(); // NOLINT
  77. }
  78. /**
  79. * Xcode will run tests from any class that extends XCTestCase, but this doesn't work for
  80. * FSTLocalStoreTests since it is incomplete without the implementations supplied by its
  81. * subclasses.
  82. */
  83. - (BOOL)isTestBaseClass {
  84. return [self class] == [FSTLocalStoreTests class];
  85. }
  86. - (void)writeMutation:(FSTMutation *)mutation {
  87. [self writeMutations:@[ mutation ]];
  88. }
  89. - (void)writeMutations:(NSArray<FSTMutation *> *)mutations {
  90. FSTLocalWriteResult *result = [self.localStore locallyWriteMutations:mutations];
  91. XCTAssertNotNil(result);
  92. [self.batches addObject:[[FSTMutationBatch alloc] initWithBatchID:result.batchID
  93. localWriteTime:[FIRTimestamp timestamp]
  94. mutations:mutations]];
  95. self.lastChanges = result.changes;
  96. }
  97. - (void)applyRemoteEvent:(FSTRemoteEvent *)event {
  98. self.lastChanges = [self.localStore applyRemoteEvent:event];
  99. }
  100. - (void)notifyLocalViewChanges:(FSTLocalViewChanges *)changes {
  101. [self.localStore notifyLocalViewChanges:@[ changes ]];
  102. }
  103. - (void)acknowledgeMutationWithVersion:(FSTTestSnapshotVersion)documentVersion {
  104. FSTMutationBatch *batch = [self.batches firstObject];
  105. [self.batches removeObjectAtIndex:0];
  106. XCTAssertEqual(batch.mutations.count, 1, @"Acknowledging more than one mutation not supported.");
  107. SnapshotVersion version = testutil::Version(documentVersion);
  108. FSTMutationResult *mutationResult =
  109. [[FSTMutationResult alloc] initWithVersion:version transformResults:nil];
  110. FSTMutationBatchResult *result = [FSTMutationBatchResult resultWithBatch:batch
  111. commitVersion:version
  112. mutationResults:@[ mutationResult ]
  113. streamToken:nil];
  114. self.lastChanges = [self.localStore acknowledgeBatchWithResult:result];
  115. }
  116. - (void)rejectMutation {
  117. FSTMutationBatch *batch = [self.batches firstObject];
  118. [self.batches removeObjectAtIndex:0];
  119. self.lastChanges = [self.localStore rejectBatchID:batch.batchID];
  120. }
  121. - (TargetId)allocateQuery:(FSTQuery *)query {
  122. FSTQueryData *queryData = [self.localStore allocateQuery:query];
  123. self.lastTargetID = queryData.targetID;
  124. return queryData.targetID;
  125. }
  126. /** Asserts that the last target ID is the given number. */
  127. #define FSTAssertTargetID(targetID) \
  128. do { \
  129. XCTAssertEqual(self.lastTargetID, targetID); \
  130. } while (0)
  131. /** Asserts that a the lastChanges contain the docs in the given array. */
  132. #define FSTAssertChanged(documents) \
  133. XCTAssertNotNil(self.lastChanges); \
  134. do { \
  135. FSTMaybeDocumentDictionary *actual = self.lastChanges; \
  136. NSArray<FSTMaybeDocument *> *expected = (documents); \
  137. XCTAssertEqual(actual.count, expected.count); \
  138. NSEnumerator<FSTMaybeDocument *> *enumerator = expected.objectEnumerator; \
  139. [actual enumerateKeysAndObjectsUsingBlock:^(FSTDocumentKey * key, FSTMaybeDocument * value, \
  140. BOOL * stop) { \
  141. XCTAssertEqualObjects(value, [enumerator nextObject]); \
  142. }]; \
  143. self.lastChanges = nil; \
  144. } while (0)
  145. /** Asserts that the given keys were removed. */
  146. #define FSTAssertRemoved(keyPaths) \
  147. XCTAssertNotNil(self.lastChanges); \
  148. do { \
  149. FSTMaybeDocumentDictionary *actual = self.lastChanges; \
  150. XCTAssertEqual(actual.count, keyPaths.count); \
  151. NSEnumerator<NSString *> *keyPathEnumerator = keyPaths.objectEnumerator; \
  152. [actual enumerateKeysAndObjectsUsingBlock:^(FSTDocumentKey * actualKey, \
  153. FSTMaybeDocument * value, BOOL * stop) { \
  154. FSTDocumentKey *expectedKey = FSTTestDocKey([keyPathEnumerator nextObject]); \
  155. XCTAssertEqualObjects(actualKey, expectedKey); \
  156. XCTAssertTrue([value isKindOfClass:[FSTDeletedDocument class]]); \
  157. }]; \
  158. self.lastChanges = nil; \
  159. } while (0)
  160. /** Asserts that the given local store contains the given document. */
  161. #define FSTAssertContains(document) \
  162. do { \
  163. FSTMaybeDocument *expected = (document); \
  164. FSTMaybeDocument *actual = [self.localStore readDocument:expected.key]; \
  165. XCTAssertEqualObjects(actual, expected); \
  166. } while (0)
  167. /** Asserts that the given local store does not contain the given document. */
  168. #define FSTAssertNotContains(keyPathString) \
  169. do { \
  170. FSTDocumentKey *key = FSTTestDocKey(keyPathString); \
  171. FSTMaybeDocument *actual = [self.localStore readDocument:key]; \
  172. XCTAssertNil(actual); \
  173. } while (0)
  174. - (void)testMutationBatchKeys {
  175. if ([self isTestBaseClass]) return;
  176. FSTMutation *set1 = FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"});
  177. FSTMutation *set2 = FSTTestSetMutation(@"bar/baz", @{@"bar" : @"baz"});
  178. FSTMutationBatch *batch = [[FSTMutationBatch alloc] initWithBatchID:1
  179. localWriteTime:[FIRTimestamp timestamp]
  180. mutations:@[ set1, set2 ]];
  181. DocumentKeySet keys = [batch keys];
  182. XCTAssertEqual(keys.size(), 2u);
  183. }
  184. - (void)testHandlesSetMutation {
  185. if ([self isTestBaseClass]) return;
  186. [self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})];
  187. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES) ]);
  188. FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES));
  189. [self acknowledgeMutationWithVersion:0];
  190. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, NO) ]);
  191. if ([self gcIsEager]) {
  192. // Nothing is pinning this anymore, as it has been acknowledged and there are no targets active.
  193. FSTAssertNotContains(@"foo/bar");
  194. } else {
  195. FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, NO));
  196. }
  197. }
  198. - (void)testHandlesSetMutationThenDocument {
  199. if ([self isTestBaseClass]) return;
  200. [self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})];
  201. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES) ]);
  202. FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES));
  203. FSTQuery *query = FSTTestQuery("foo");
  204. TargetId targetID = [self allocateQuery:query];
  205. [self
  206. applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 2, @{@"it" : @"changed"}, NO),
  207. @[ @(targetID) ], @[])];
  208. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, YES) ]);
  209. FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, YES));
  210. }
  211. - (void)testHandlesAckThenRejectThenRemoteEvent {
  212. if ([self isTestBaseClass]) return;
  213. // Start a query that requires acks to be held.
  214. FSTQuery *query = FSTTestQuery("foo");
  215. TargetId targetID = [self allocateQuery:query];
  216. [self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})];
  217. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES) ]);
  218. FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES));
  219. // The last seen version is zero, so this ack must be held.
  220. [self acknowledgeMutationWithVersion:1];
  221. FSTAssertChanged(@[]);
  222. FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES));
  223. [self writeMutation:FSTTestSetMutation(@"bar/baz", @{@"bar" : @"baz"})];
  224. FSTAssertChanged(@[ FSTTestDoc("bar/baz", 0, @{@"bar" : @"baz"}, YES) ]);
  225. FSTAssertContains(FSTTestDoc("bar/baz", 0, @{@"bar" : @"baz"}, YES));
  226. [self rejectMutation];
  227. FSTAssertRemoved(@[ @"bar/baz" ]);
  228. FSTAssertNotContains(@"bar/baz");
  229. [self
  230. applyRemoteEvent:FSTTestAddedRemoteEvent(FSTTestDoc("foo/bar", 2, @{@"it" : @"changed"}, NO),
  231. @[ @(targetID) ])];
  232. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 2, @{@"it" : @"changed"}, NO) ]);
  233. FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"it" : @"changed"}, NO));
  234. FSTAssertNotContains(@"bar/baz");
  235. }
  236. - (void)testHandlesDeletedDocumentThenSetMutationThenAck {
  237. if ([self isTestBaseClass]) return;
  238. FSTQuery *query = FSTTestQuery("foo");
  239. TargetId targetID = [self allocateQuery:query];
  240. [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDeletedDoc("foo/bar", 2), @[ @(targetID) ],
  241. @[])];
  242. FSTAssertRemoved(@[ @"foo/bar" ]);
  243. // Under eager GC, there is no longer a reference for the document, and it should be
  244. // deleted.
  245. if (![self gcIsEager]) {
  246. FSTAssertContains(FSTTestDeletedDoc("foo/bar", 2));
  247. } else {
  248. FSTAssertNotContains(@"foo/bar");
  249. }
  250. [self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})];
  251. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES) ]);
  252. FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES));
  253. // Can now remove the target, since we have a mutation pinning the document
  254. [self.localStore releaseQuery:query];
  255. // Verify we didn't lose anything
  256. FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES));
  257. [self acknowledgeMutationWithVersion:3];
  258. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, NO) ]);
  259. // It has been acknowledged, and should no longer be retained as there is no target and mutation
  260. if ([self gcIsEager]) {
  261. FSTAssertNotContains(@"foo/bar");
  262. }
  263. }
  264. - (void)testHandlesSetMutationThenDeletedDocument {
  265. if ([self isTestBaseClass]) return;
  266. FSTQuery *query = FSTTestQuery("foo");
  267. TargetId targetID = [self allocateQuery:query];
  268. [self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})];
  269. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES) ]);
  270. [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDeletedDoc("foo/bar", 2), @[ @(targetID) ],
  271. @[])];
  272. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES) ]);
  273. FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES));
  274. }
  275. - (void)testHandlesDocumentThenSetMutationThenAckThenDocument {
  276. if ([self isTestBaseClass]) return;
  277. // Start a query that requires acks to be held.
  278. FSTQuery *query = FSTTestQuery("foo");
  279. TargetId targetID = [self allocateQuery:query];
  280. [self applyRemoteEvent:FSTTestAddedRemoteEvent(FSTTestDoc("foo/bar", 2, @{@"it" : @"base"}, NO),
  281. @[ @(targetID) ])];
  282. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 2, @{@"it" : @"base"}, NO) ]);
  283. FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"it" : @"base"}, NO));
  284. [self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})];
  285. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, YES) ]);
  286. FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, YES));
  287. [self acknowledgeMutationWithVersion:3];
  288. // we haven't seen the remote event yet, so the write is still held.
  289. FSTAssertChanged(@[]);
  290. FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, YES));
  291. [self
  292. applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 3, @{@"it" : @"changed"}, NO),
  293. @[ @(targetID) ], @[])];
  294. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 3, @{@"it" : @"changed"}, NO) ]);
  295. FSTAssertContains(FSTTestDoc("foo/bar", 3, @{@"it" : @"changed"}, NO));
  296. }
  297. - (void)testHandlesPatchWithoutPriorDocument {
  298. if ([self isTestBaseClass]) return;
  299. [self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})];
  300. FSTAssertRemoved(@[ @"foo/bar" ]);
  301. FSTAssertNotContains(@"foo/bar");
  302. [self acknowledgeMutationWithVersion:1];
  303. FSTAssertRemoved(@[ @"foo/bar" ]);
  304. FSTAssertNotContains(@"foo/bar");
  305. }
  306. - (void)testHandlesPatchMutationThenDocumentThenAck {
  307. if ([self isTestBaseClass]) return;
  308. [self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})];
  309. FSTAssertRemoved(@[ @"foo/bar" ]);
  310. FSTAssertNotContains(@"foo/bar");
  311. FSTQuery *query = FSTTestQuery("foo");
  312. TargetId targetID = [self allocateQuery:query];
  313. [self applyRemoteEvent:FSTTestAddedRemoteEvent(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO),
  314. @[ @(targetID) ])];
  315. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar", @"it" : @"base"}, YES) ]);
  316. FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar", @"it" : @"base"}, YES));
  317. [self acknowledgeMutationWithVersion:2];
  318. // We still haven't seen the remote events for the patch, so the local changes remain, and there
  319. // are no changes
  320. FSTAssertChanged(@[]);
  321. FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar", @"it" : @"base"}, YES));
  322. [self applyRemoteEvent:FSTTestUpdateRemoteEvent(
  323. FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar", @"it" : @"base"}, NO), @[],
  324. @[])];
  325. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar", @"it" : @"base"}, NO) ]);
  326. FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar", @"it" : @"base"}, NO));
  327. }
  328. - (void)testHandlesPatchMutationThenAckThenDocument {
  329. if ([self isTestBaseClass]) return;
  330. [self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})];
  331. FSTAssertRemoved(@[ @"foo/bar" ]);
  332. FSTAssertNotContains(@"foo/bar");
  333. [self acknowledgeMutationWithVersion:1];
  334. FSTAssertRemoved(@[ @"foo/bar" ]);
  335. FSTAssertNotContains(@"foo/bar");
  336. FSTQuery *query = FSTTestQuery("foo");
  337. TargetId targetID = [self allocateQuery:query];
  338. [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO),
  339. @[ @(targetID) ], @[])];
  340. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO) ]);
  341. FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO));
  342. }
  343. - (void)testHandlesDeleteMutationThenAck {
  344. if ([self isTestBaseClass]) return;
  345. [self writeMutation:FSTTestDeleteMutation(@"foo/bar")];
  346. FSTAssertRemoved(@[ @"foo/bar" ]);
  347. FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0));
  348. [self acknowledgeMutationWithVersion:1];
  349. FSTAssertRemoved(@[ @"foo/bar" ]);
  350. // There's no target pinning the doc, and we've ack'd the mutation.
  351. if ([self gcIsEager]) {
  352. FSTAssertNotContains(@"foo/bar");
  353. }
  354. }
  355. - (void)testHandlesDocumentThenDeleteMutationThenAck {
  356. if ([self isTestBaseClass]) return;
  357. FSTQuery *query = FSTTestQuery("foo");
  358. TargetId targetID = [self allocateQuery:query];
  359. [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO),
  360. @[ @(targetID) ], @[])];
  361. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO) ]);
  362. FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO));
  363. [self writeMutation:FSTTestDeleteMutation(@"foo/bar")];
  364. FSTAssertRemoved(@[ @"foo/bar" ]);
  365. FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0));
  366. // Remove the target so only the mutation is pinning the document
  367. [self.localStore releaseQuery:query];
  368. [self acknowledgeMutationWithVersion:2];
  369. FSTAssertRemoved(@[ @"foo/bar" ]);
  370. if ([self gcIsEager]) {
  371. // Neither the target nor the mutation pin the document, it should be gone.
  372. FSTAssertNotContains(@"foo/bar");
  373. }
  374. }
  375. - (void)testHandlesDeleteMutationThenDocumentThenAck {
  376. if ([self isTestBaseClass]) return;
  377. FSTQuery *query = FSTTestQuery("foo");
  378. TargetId targetID = [self allocateQuery:query];
  379. [self writeMutation:FSTTestDeleteMutation(@"foo/bar")];
  380. FSTAssertRemoved(@[ @"foo/bar" ]);
  381. FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0));
  382. // Add the document to a target so it will remain in persistence even when ack'd
  383. [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO),
  384. @[ @(targetID) ], @[])];
  385. FSTAssertRemoved(@[ @"foo/bar" ]);
  386. FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0));
  387. // Don't need to keep it pinned anymore
  388. [self.localStore releaseQuery:query];
  389. [self acknowledgeMutationWithVersion:2];
  390. FSTAssertRemoved(@[ @"foo/bar" ]);
  391. if ([self gcIsEager]) {
  392. // The doc is not pinned in a target and we've acknowledged the mutation. It shouldn't exist
  393. // anymore.
  394. FSTAssertNotContains(@"foo/bar");
  395. }
  396. }
  397. - (void)testHandlesDocumentThenDeletedDocumentThenDocument {
  398. if ([self isTestBaseClass]) return;
  399. FSTQuery *query = FSTTestQuery("foo");
  400. TargetId targetID = [self allocateQuery:query];
  401. [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO),
  402. @[ @(targetID) ], @[])];
  403. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO) ]);
  404. FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO));
  405. [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDeletedDoc("foo/bar", 2), @[ @(targetID) ],
  406. @[])];
  407. FSTAssertRemoved(@[ @"foo/bar" ]);
  408. if (![self gcIsEager]) {
  409. FSTAssertContains(FSTTestDeletedDoc("foo/bar", 2));
  410. }
  411. [self
  412. applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 3, @{@"it" : @"changed"}, NO),
  413. @[ @(targetID) ], @[])];
  414. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 3, @{@"it" : @"changed"}, NO) ]);
  415. FSTAssertContains(FSTTestDoc("foo/bar", 3, @{@"it" : @"changed"}, NO));
  416. }
  417. - (void)testHandlesSetMutationThenPatchMutationThenDocumentThenAckThenAck {
  418. if ([self isTestBaseClass]) return;
  419. [self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"old"})];
  420. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"old"}, YES) ]);
  421. FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"old"}, YES));
  422. [self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})];
  423. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES) ]);
  424. FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES));
  425. FSTQuery *query = FSTTestQuery("foo");
  426. TargetId targetID = [self allocateQuery:query];
  427. [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO),
  428. @[ @(targetID) ], @[])];
  429. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, YES) ]);
  430. FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, YES));
  431. [self.localStore releaseQuery:query];
  432. [self acknowledgeMutationWithVersion:2]; // delete mutation
  433. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, YES) ]);
  434. FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, YES));
  435. [self acknowledgeMutationWithVersion:3]; // patch mutation
  436. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, NO) ]);
  437. if ([self gcIsEager]) {
  438. // we've ack'd all of the mutations, nothing is keeping this pinned anymore
  439. FSTAssertNotContains(@"foo/bar");
  440. }
  441. }
  442. - (void)testHandlesSetMutationAndPatchMutationTogether {
  443. if ([self isTestBaseClass]) return;
  444. [self writeMutations:@[
  445. FSTTestSetMutation(@"foo/bar", @{@"foo" : @"old"}),
  446. FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})
  447. ]];
  448. FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES) ]);
  449. FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES));
  450. }
  451. - (void)testHandlesSetMutationThenPatchMutationThenReject {
  452. if ([self isTestBaseClass]) return;
  453. if (![self gcIsEager]) return;
  454. [self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"old"})];
  455. FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"old"}, YES));
  456. [self acknowledgeMutationWithVersion:1];
  457. FSTAssertNotContains(@"foo/bar");
  458. [self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})];
  459. // A blind patch is not visible in the cache
  460. FSTAssertNotContains(@"foo/bar");
  461. [self rejectMutation];
  462. FSTAssertNotContains(@"foo/bar");
  463. }
  464. - (void)testHandlesSetMutationsAndPatchMutationOfJustOneTogether {
  465. if ([self isTestBaseClass]) return;
  466. [self writeMutations:@[
  467. FSTTestSetMutation(@"foo/bar", @{@"foo" : @"old"}),
  468. FSTTestSetMutation(@"bar/baz", @{@"bar" : @"baz"}),
  469. FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})
  470. ]];
  471. FSTAssertChanged((@[
  472. FSTTestDoc("bar/baz", 0, @{@"bar" : @"baz"}, YES),
  473. FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES)
  474. ]));
  475. FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES));
  476. FSTAssertContains(FSTTestDoc("bar/baz", 0, @{@"bar" : @"baz"}, YES));
  477. }
  478. - (void)testHandlesDeleteMutationThenPatchMutationThenAckThenAck {
  479. if ([self isTestBaseClass]) return;
  480. [self writeMutation:FSTTestDeleteMutation(@"foo/bar")];
  481. FSTAssertRemoved(@[ @"foo/bar" ]);
  482. FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0));
  483. [self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})];
  484. FSTAssertRemoved(@[ @"foo/bar" ]);
  485. FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0));
  486. [self acknowledgeMutationWithVersion:2]; // delete mutation
  487. FSTAssertRemoved(@[ @"foo/bar" ]);
  488. FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0));
  489. [self acknowledgeMutationWithVersion:3]; // patch mutation
  490. FSTAssertRemoved(@[ @"foo/bar" ]);
  491. if ([self gcIsEager]) {
  492. // There are no more pending mutations, the doc has been dropped
  493. FSTAssertNotContains(@"foo/bar");
  494. }
  495. }
  496. - (void)testCollectsGarbageAfterChangeBatchWithNoTargetIDs {
  497. if ([self isTestBaseClass]) return;
  498. if (![self gcIsEager]) return;
  499. [self applyRemoteEvent:FSTTestUpdateRemoteEventWithLimboTargets(FSTTestDeletedDoc("foo/bar", 2),
  500. @[], @[], @[ @1 ])];
  501. FSTAssertNotContains(@"foo/bar");
  502. [self applyRemoteEvent:FSTTestUpdateRemoteEventWithLimboTargets(
  503. FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, NO), @[], @[], @[ @1 ])];
  504. FSTAssertNotContains(@"foo/bar");
  505. }
  506. - (void)testCollectsGarbageAfterChangeBatch {
  507. if ([self isTestBaseClass]) return;
  508. if (![self gcIsEager]) return;
  509. FSTQuery *query = FSTTestQuery("foo");
  510. TargetId targetID = [self allocateQuery:query];
  511. [self applyRemoteEvent:FSTTestAddedRemoteEvent(FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, NO),
  512. @[ @(targetID) ])];
  513. FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, NO));
  514. [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 2, @{@"foo" : @"baz"}, NO),
  515. @[], @[ @(targetID) ])];
  516. FSTAssertNotContains(@"foo/bar");
  517. }
  518. - (void)testCollectsGarbageAfterAcknowledgedMutation {
  519. if ([self isTestBaseClass]) return;
  520. if (![self gcIsEager]) return;
  521. FSTQuery *query = FSTTestQuery("foo");
  522. TargetId targetID = [self allocateQuery:query];
  523. [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 0, @{@"foo" : @"old"}, NO),
  524. @[ @(targetID) ], @[])];
  525. [self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})];
  526. // Release the query so that our target count goes back to 0 and we are considered up-to-date.
  527. [self.localStore releaseQuery:query];
  528. [self writeMutation:FSTTestSetMutation(@"foo/bah", @{@"foo" : @"bah"})];
  529. [self writeMutation:FSTTestDeleteMutation(@"foo/baz")];
  530. FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES));
  531. FSTAssertContains(FSTTestDoc("foo/bah", 0, @{@"foo" : @"bah"}, YES));
  532. FSTAssertContains(FSTTestDeletedDoc("foo/baz", 0));
  533. [self acknowledgeMutationWithVersion:3];
  534. FSTAssertNotContains(@"foo/bar");
  535. FSTAssertContains(FSTTestDoc("foo/bah", 0, @{@"foo" : @"bah"}, YES));
  536. FSTAssertContains(FSTTestDeletedDoc("foo/baz", 0));
  537. [self acknowledgeMutationWithVersion:4];
  538. FSTAssertNotContains(@"foo/bar");
  539. FSTAssertNotContains(@"foo/bah");
  540. FSTAssertContains(FSTTestDeletedDoc("foo/baz", 0));
  541. [self acknowledgeMutationWithVersion:5];
  542. FSTAssertNotContains(@"foo/bar");
  543. FSTAssertNotContains(@"foo/bah");
  544. FSTAssertNotContains(@"foo/baz");
  545. }
  546. - (void)testCollectsGarbageAfterRejectedMutation {
  547. if ([self isTestBaseClass]) return;
  548. if (![self gcIsEager]) return;
  549. FSTQuery *query = FSTTestQuery("foo");
  550. TargetId targetID = [self allocateQuery:query];
  551. [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 0, @{@"foo" : @"old"}, NO),
  552. @[ @(targetID) ], @[])];
  553. [self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})];
  554. // Release the query so that our target count goes back to 0 and we are considered up-to-date.
  555. [self.localStore releaseQuery:query];
  556. [self writeMutation:FSTTestSetMutation(@"foo/bah", @{@"foo" : @"bah"})];
  557. [self writeMutation:FSTTestDeleteMutation(@"foo/baz")];
  558. FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES));
  559. FSTAssertContains(FSTTestDoc("foo/bah", 0, @{@"foo" : @"bah"}, YES));
  560. FSTAssertContains(FSTTestDeletedDoc("foo/baz", 0));
  561. [self rejectMutation]; // patch mutation
  562. FSTAssertNotContains(@"foo/bar");
  563. FSTAssertContains(FSTTestDoc("foo/bah", 0, @{@"foo" : @"bah"}, YES));
  564. FSTAssertContains(FSTTestDeletedDoc("foo/baz", 0));
  565. [self rejectMutation]; // set mutation
  566. FSTAssertNotContains(@"foo/bar");
  567. FSTAssertNotContains(@"foo/bah");
  568. FSTAssertContains(FSTTestDeletedDoc("foo/baz", 0));
  569. [self rejectMutation]; // delete mutation
  570. FSTAssertNotContains(@"foo/bar");
  571. FSTAssertNotContains(@"foo/bah");
  572. FSTAssertNotContains(@"foo/baz");
  573. }
  574. - (void)testPinsDocumentsInTheLocalView {
  575. if ([self isTestBaseClass]) return;
  576. if (![self gcIsEager]) return;
  577. FSTQuery *query = FSTTestQuery("foo");
  578. TargetId targetID = [self allocateQuery:query];
  579. [self applyRemoteEvent:FSTTestAddedRemoteEvent(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, NO),
  580. @[ @(targetID) ])];
  581. [self writeMutation:FSTTestSetMutation(@"foo/baz", @{@"foo" : @"baz"})];
  582. FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, NO));
  583. FSTAssertContains(FSTTestDoc("foo/baz", 0, @{@"foo" : @"baz"}, YES));
  584. [self notifyLocalViewChanges:FSTTestViewChanges(targetID, @[ @"foo/bar", @"foo/baz" ], @[])];
  585. FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, NO));
  586. [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, NO),
  587. @[], @[ @(targetID) ])];
  588. [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/baz", 2, @{@"foo" : @"baz"}, NO),
  589. @[ @(targetID) ], @[])];
  590. FSTAssertContains(FSTTestDoc("foo/baz", 2, @{@"foo" : @"baz"}, YES));
  591. [self acknowledgeMutationWithVersion:2];
  592. FSTAssertContains(FSTTestDoc("foo/baz", 2, @{@"foo" : @"baz"}, NO));
  593. FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, NO));
  594. FSTAssertContains(FSTTestDoc("foo/baz", 2, @{@"foo" : @"baz"}, NO));
  595. [self notifyLocalViewChanges:FSTTestViewChanges(targetID, @[], @[ @"foo/bar", @"foo/baz" ])];
  596. [self.localStore releaseQuery:query];
  597. FSTAssertNotContains(@"foo/bar");
  598. FSTAssertNotContains(@"foo/baz");
  599. }
  600. - (void)testThrowsAwayDocumentsWithUnknownTargetIDsImmediately {
  601. if ([self isTestBaseClass]) return;
  602. if (![self gcIsEager]) return;
  603. TargetId targetID = 321;
  604. [self applyRemoteEvent:FSTTestUpdateRemoteEventWithLimboTargets(FSTTestDoc("foo/bar", 1, @{}, NO),
  605. @[], @[], @[ @(targetID) ])];
  606. FSTAssertNotContains(@"foo/bar");
  607. }
  608. - (void)testCanExecuteDocumentQueries {
  609. if ([self isTestBaseClass]) return;
  610. [self.localStore locallyWriteMutations:@[
  611. FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"}),
  612. FSTTestSetMutation(@"foo/baz", @{@"foo" : @"baz"}),
  613. FSTTestSetMutation(@"foo/bar/Foo/Bar", @{@"Foo" : @"Bar"})
  614. ]];
  615. FSTQuery *query = FSTTestQuery("foo/bar");
  616. FSTDocumentDictionary *docs = [self.localStore executeQuery:query];
  617. XCTAssertEqualObjects([docs values], @[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES) ]);
  618. }
  619. - (void)testCanExecuteCollectionQueries {
  620. if ([self isTestBaseClass]) return;
  621. [self.localStore locallyWriteMutations:@[
  622. FSTTestSetMutation(@"fo/bar", @{@"fo" : @"bar"}),
  623. FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"}),
  624. FSTTestSetMutation(@"foo/baz", @{@"foo" : @"baz"}),
  625. FSTTestSetMutation(@"foo/bar/Foo/Bar", @{@"Foo" : @"Bar"}),
  626. FSTTestSetMutation(@"fooo/blah", @{@"fooo" : @"blah"})
  627. ]];
  628. FSTQuery *query = FSTTestQuery("foo");
  629. FSTDocumentDictionary *docs = [self.localStore executeQuery:query];
  630. XCTAssertEqualObjects([docs values], (@[
  631. FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES),
  632. FSTTestDoc("foo/baz", 0, @{@"foo" : @"baz"}, YES)
  633. ]));
  634. }
  635. - (void)testCanExecuteMixedCollectionQueries {
  636. if ([self isTestBaseClass]) return;
  637. FSTQuery *query = FSTTestQuery("foo");
  638. [self allocateQuery:query];
  639. FSTAssertTargetID(2);
  640. [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/baz", 10, @{@"a" : @"b"}, NO),
  641. @[ @2 ], @[])];
  642. [self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 20, @{@"a" : @"b"}, NO),
  643. @[ @2 ], @[])];
  644. [self.localStore locallyWriteMutations:@[ FSTTestSetMutation(@"foo/bonk", @{@"a" : @"b"}) ]];
  645. FSTDocumentDictionary *docs = [self.localStore executeQuery:query];
  646. XCTAssertEqualObjects([docs values], (@[
  647. FSTTestDoc("foo/bar", 20, @{@"a" : @"b"}, NO),
  648. FSTTestDoc("foo/baz", 10, @{@"a" : @"b"}, NO),
  649. FSTTestDoc("foo/bonk", 0, @{@"a" : @"b"}, YES)
  650. ]));
  651. }
  652. - (void)testPersistsResumeTokens {
  653. if ([self isTestBaseClass]) return;
  654. // This test only works in the absence of the FSTEagerGarbageCollector.
  655. if ([self gcIsEager]) return;
  656. FSTQuery *query = FSTTestQuery("foo/bar");
  657. FSTQueryData *queryData = [self.localStore allocateQuery:query];
  658. ListenSequenceNumber initialSequenceNumber = queryData.sequenceNumber;
  659. FSTBoxedTargetID *targetID = @(queryData.targetID);
  660. NSData *resumeToken = FSTTestResumeTokenFromSnapshotVersion(1000);
  661. FSTWatchTargetChange *watchChange =
  662. [FSTWatchTargetChange changeWithState:FSTWatchTargetChangeStateCurrent
  663. targetIDs:@[ targetID ]
  664. resumeToken:resumeToken];
  665. NSMutableDictionary<FSTBoxedTargetID *, FSTQueryData *> *listens =
  666. [NSMutableDictionary dictionary];
  667. listens[targetID] = queryData;
  668. FSTWatchChangeAggregator *aggregator = [[FSTWatchChangeAggregator alloc]
  669. initWithTargetMetadataProvider:[FSTTestTargetMetadataProvider
  670. providerWithSingleResultForKey:testutil::Key("foo/bar")
  671. targets:@[ targetID ]]];
  672. [aggregator handleTargetChange:watchChange];
  673. FSTRemoteEvent *remoteEvent = [aggregator remoteEventAtSnapshotVersion:testutil::Version(1000)];
  674. [self applyRemoteEvent:remoteEvent];
  675. // Stop listening so that the query should become inactive (but persistent)
  676. [self.localStore releaseQuery:query];
  677. // Should come back with the same resume token
  678. FSTQueryData *queryData2 = [self.localStore allocateQuery:query];
  679. XCTAssertEqualObjects(queryData2.resumeToken, resumeToken);
  680. // The sequence number should have been bumped when we saved the new resume token.
  681. ListenSequenceNumber newSequenceNumber = queryData2.sequenceNumber;
  682. XCTAssertGreaterThan(newSequenceNumber, initialSequenceNumber);
  683. }
  684. - (void)testRemoteDocumentKeysForTarget {
  685. if ([self isTestBaseClass]) return;
  686. FSTQuery *query = FSTTestQuery("foo");
  687. [self allocateQuery:query];
  688. FSTAssertTargetID(2);
  689. [self applyRemoteEvent:FSTTestAddedRemoteEvent(FSTTestDoc("foo/baz", 10, @{@"a" : @"b"}, NO),
  690. @[ @2 ])];
  691. [self applyRemoteEvent:FSTTestAddedRemoteEvent(FSTTestDoc("foo/bar", 20, @{@"a" : @"b"}, NO),
  692. @[ @2 ])];
  693. [self.localStore locallyWriteMutations:@[ FSTTestSetMutation(@"foo/bonk", @{@"a" : @"b"}) ]];
  694. DocumentKeySet keys = [self.localStore remoteDocumentKeysForTarget:2];
  695. DocumentKeySet expected{testutil::Key("foo/bar"), testutil::Key("foo/baz")};
  696. XCTAssertEqual(keys, expected);
  697. keys = [self.localStore remoteDocumentKeysForTarget:2];
  698. XCTAssertEqual(keys, (DocumentKeySet{testutil::Key("foo/bar"), testutil::Key("foo/baz")}));
  699. }
  700. @end
  701. NS_ASSUME_NONNULL_END