FSTLocalStoreTests.mm 36 KB

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