FSTLocalStoreTests.mm 36 KB

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