FSTSyncEngineTestDriver.mm 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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/Example/Tests/SpecTests/FSTSyncEngineTestDriver.h"
  17. #import <FirebaseFirestore/FIRFirestoreErrors.h>
  18. #include <cstddef>
  19. #include <map>
  20. #include <memory>
  21. #include <string>
  22. #include <unordered_map>
  23. #include <utility>
  24. #include <vector>
  25. #import "Firestore/Example/Tests/SpecTests/FSTMockDatastore.h"
  26. #include "Firestore/core/include/firebase/firestore/firestore_errors.h"
  27. #include "Firestore/core/src/api/load_bundle_task.h"
  28. #include "Firestore/core/src/bundle/bundle_reader.h"
  29. #include "Firestore/core/src/core/database_info.h"
  30. #include "Firestore/core/src/core/event_manager.h"
  31. #include "Firestore/core/src/core/listen_options.h"
  32. #include "Firestore/core/src/core/query_listener.h"
  33. #include "Firestore/core/src/core/sync_engine.h"
  34. #include "Firestore/core/src/credentials/empty_credentials_provider.h"
  35. #include "Firestore/core/src/credentials/user.h"
  36. #include "Firestore/core/src/local/local_store.h"
  37. #include "Firestore/core/src/local/persistence.h"
  38. #include "Firestore/core/src/local/query_engine.h"
  39. #include "Firestore/core/src/model/database_id.h"
  40. #include "Firestore/core/src/model/document_key.h"
  41. #include "Firestore/core/src/remote/firebase_metadata_provider.h"
  42. #include "Firestore/core/src/remote/firebase_metadata_provider_noop.h"
  43. #include "Firestore/core/src/remote/remote_store.h"
  44. #include "Firestore/core/src/util/async_queue.h"
  45. #include "Firestore/core/src/util/delayed_constructor.h"
  46. #include "Firestore/core/src/util/error_apple.h"
  47. #include "Firestore/core/src/util/executor.h"
  48. #include "Firestore/core/src/util/hard_assert.h"
  49. #include "Firestore/core/src/util/log.h"
  50. #include "Firestore/core/src/util/status.h"
  51. #include "Firestore/core/src/util/statusor.h"
  52. #include "Firestore/core/src/util/string_format.h"
  53. #include "Firestore/core/src/util/to_string.h"
  54. #include "Firestore/core/test/unit/remote/create_noop_connectivity_monitor.h"
  55. #include "Firestore/core/test/unit/testutil/async_testing.h"
  56. #include "absl/memory/memory.h"
  57. using firebase::firestore::Error;
  58. using firebase::firestore::api::LoadBundleTask;
  59. using firebase::firestore::bundle::BundleReader;
  60. using firebase::firestore::core::DatabaseInfo;
  61. using firebase::firestore::core::EventListener;
  62. using firebase::firestore::core::EventManager;
  63. using firebase::firestore::core::ListenOptions;
  64. using firebase::firestore::core::Query;
  65. using firebase::firestore::core::QueryListener;
  66. using firebase::firestore::core::SyncEngine;
  67. using firebase::firestore::core::ViewSnapshot;
  68. using firebase::firestore::credentials::EmptyAppCheckCredentialsProvider;
  69. using firebase::firestore::credentials::EmptyAuthCredentialsProvider;
  70. using firebase::firestore::credentials::HashUser;
  71. using firebase::firestore::credentials::User;
  72. using firebase::firestore::local::LocalStore;
  73. using firebase::firestore::local::Persistence;
  74. using firebase::firestore::local::QueryEngine;
  75. using firebase::firestore::local::TargetData;
  76. using firebase::firestore::model::DatabaseId;
  77. using firebase::firestore::model::DocumentKey;
  78. using firebase::firestore::model::DocumentKeySet;
  79. using firebase::firestore::model::Mutation;
  80. using firebase::firestore::model::MutationResult;
  81. using firebase::firestore::model::OnlineState;
  82. using firebase::firestore::model::SnapshotVersion;
  83. using firebase::firestore::model::TargetId;
  84. using firebase::firestore::remote::ConnectivityMonitor;
  85. using firebase::firestore::remote::CreateFirebaseMetadataProviderNoOp;
  86. using firebase::firestore::remote::CreateNoOpConnectivityMonitor;
  87. using firebase::firestore::remote::FirebaseMetadataProvider;
  88. using firebase::firestore::remote::MockDatastore;
  89. using firebase::firestore::remote::RemoteStore;
  90. using firebase::firestore::remote::WatchChange;
  91. using firebase::firestore::testutil::AsyncQueueForTesting;
  92. using firebase::firestore::util::AsyncQueue;
  93. using firebase::firestore::util::DelayedConstructor;
  94. using firebase::firestore::util::Empty;
  95. using firebase::firestore::util::Executor;
  96. using firebase::firestore::util::MakeNSError;
  97. using firebase::firestore::util::MakeNSString;
  98. using firebase::firestore::util::MakeString;
  99. using firebase::firestore::util::Status;
  100. using firebase::firestore::util::StatusOr;
  101. using firebase::firestore::util::StringFormat;
  102. using firebase::firestore::util::TimerId;
  103. using firebase::firestore::util::ToString;
  104. NS_ASSUME_NONNULL_BEGIN
  105. @implementation FSTQueryEvent {
  106. absl::optional<ViewSnapshot> _maybeViewSnapshot;
  107. }
  108. - (const absl::optional<ViewSnapshot> &)viewSnapshot {
  109. return _maybeViewSnapshot;
  110. }
  111. - (void)setViewSnapshot:(absl::optional<ViewSnapshot>)snapshot {
  112. _maybeViewSnapshot = std::move(snapshot);
  113. }
  114. - (NSString *)description {
  115. // The Query is also included in the view, so we skip it.
  116. std::string str = StringFormat("<FSTQueryEvent: viewSnapshot=%s, error=%s>",
  117. ToString(_maybeViewSnapshot), self.error);
  118. return MakeNSString(str);
  119. }
  120. @end
  121. @implementation FSTOutstandingWrite {
  122. Mutation _write;
  123. }
  124. - (const model::Mutation &)write {
  125. return _write;
  126. }
  127. - (void)setWrite:(model::Mutation)write {
  128. _write = std::move(write);
  129. }
  130. @end
  131. @interface FSTSyncEngineTestDriver ()
  132. #pragma mark - Parts of the Firestore system that the spec tests need to control.
  133. #pragma mark - Data structures for holding events sent by the watch stream.
  134. /** A block for the FSTEventAggregator to use to report events to the test. */
  135. @property(nonatomic, strong, readonly) void (^eventHandler)(FSTQueryEvent *);
  136. /** The events received by our eventHandler and not yet retrieved via capturedEventsSinceLastCall */
  137. @property(nonatomic, strong, readonly) NSMutableArray<FSTQueryEvent *> *events;
  138. #pragma mark - Data structures for holding events sent by the write stream.
  139. /** The names of the documents that the client acknowledged during the current spec test step */
  140. @property(nonatomic, strong, readonly) NSMutableArray<NSString *> *acknowledgedDocs;
  141. /** The names of the documents that the client rejected during the current spec test step */
  142. @property(nonatomic, strong, readonly) NSMutableArray<NSString *> *rejectedDocs;
  143. @end
  144. @implementation FSTSyncEngineTestDriver {
  145. size_t _maxConcurrentLimboResolutions;
  146. std::unique_ptr<Persistence> _persistence;
  147. std::unique_ptr<LocalStore> _localStore;
  148. std::unique_ptr<SyncEngine> _syncEngine;
  149. std::shared_ptr<AsyncQueue> _workerQueue;
  150. std::unique_ptr<RemoteStore> _remoteStore;
  151. std::unique_ptr<ConnectivityMonitor> _connectivityMonitor;
  152. std::unique_ptr<FirebaseMetadataProvider> _firebaseMetadataProvider;
  153. DelayedConstructor<EventManager> _eventManager;
  154. // Set of active targets, keyed by target Id, mapped to corresponding resume token,
  155. // and list of `TargetData`.
  156. ActiveTargetMap _expectedActiveTargets;
  157. // ivar is declared as mutable.
  158. std::unordered_map<User, NSMutableArray<FSTOutstandingWrite *> *, HashUser> _outstandingWrites;
  159. DocumentKeySet _expectedActiveLimboDocuments;
  160. DocumentKeySet _expectedEnqueuedLimboDocuments;
  161. /** A dictionary for tracking the listens on queries. */
  162. std::unordered_map<Query, std::shared_ptr<QueryListener>> _queryListeners;
  163. DatabaseInfo _databaseInfo;
  164. User _currentUser;
  165. std::vector<std::shared_ptr<EventListener<Empty>>> _snapshotsInSyncListeners;
  166. std::shared_ptr<MockDatastore> _datastore;
  167. QueryEngine _queryEngine;
  168. int _snapshotsInSyncEvents;
  169. int _waitForPendingWritesEvents;
  170. }
  171. - (instancetype)initWithPersistence:(std::unique_ptr<Persistence>)persistence
  172. initialUser:(const User &)initialUser
  173. outstandingWrites:(const FSTOutstandingWriteQueues &)outstandingWrites
  174. maxConcurrentLimboResolutions:(size_t)maxConcurrentLimboResolutions {
  175. if (self = [super init]) {
  176. _maxConcurrentLimboResolutions = maxConcurrentLimboResolutions;
  177. // Do a deep copy.
  178. for (const auto &pair : outstandingWrites) {
  179. _outstandingWrites[pair.first] = [pair.second mutableCopy];
  180. }
  181. _events = [NSMutableArray array];
  182. _databaseInfo = {DatabaseId{"test-project", "(default)"}, "persistence", "host", false};
  183. // Set up the sync engine and various stores.
  184. _workerQueue = AsyncQueueForTesting();
  185. _persistence = std::move(persistence);
  186. _localStore = absl::make_unique<LocalStore>(_persistence.get(), &_queryEngine, initialUser);
  187. _connectivityMonitor = CreateNoOpConnectivityMonitor();
  188. _firebaseMetadataProvider = CreateFirebaseMetadataProviderNoOp();
  189. _datastore = std::make_shared<MockDatastore>(
  190. _databaseInfo, _workerQueue, std::make_shared<EmptyAuthCredentialsProvider>(),
  191. std::make_shared<EmptyAppCheckCredentialsProvider>(), _connectivityMonitor.get(),
  192. _firebaseMetadataProvider.get());
  193. _remoteStore = absl::make_unique<RemoteStore>(
  194. _localStore.get(), _datastore, _workerQueue, _connectivityMonitor.get(),
  195. [self](OnlineState onlineState) { _syncEngine->HandleOnlineStateChange(onlineState); });
  196. ;
  197. _syncEngine = absl::make_unique<SyncEngine>(_localStore.get(), _remoteStore.get(), initialUser,
  198. _maxConcurrentLimboResolutions);
  199. _remoteStore->set_sync_engine(_syncEngine.get());
  200. _eventManager.Init(_syncEngine.get());
  201. // Set up internal event tracking for the spec tests.
  202. NSMutableArray<FSTQueryEvent *> *events = [NSMutableArray array];
  203. _eventHandler = ^(FSTQueryEvent *e) {
  204. [events addObject:e];
  205. };
  206. _events = events;
  207. _currentUser = initialUser;
  208. _acknowledgedDocs = [NSMutableArray array];
  209. _rejectedDocs = [NSMutableArray array];
  210. }
  211. return self;
  212. }
  213. - (const FSTOutstandingWriteQueues &)outstandingWrites {
  214. return _outstandingWrites;
  215. }
  216. - (const DocumentKeySet &)expectedActiveLimboDocuments {
  217. return _expectedActiveLimboDocuments;
  218. }
  219. - (void)setExpectedActiveLimboDocuments:(DocumentKeySet)docs {
  220. _expectedActiveLimboDocuments = std::move(docs);
  221. }
  222. - (const DocumentKeySet &)expectedEnqueuedLimboDocuments {
  223. return _expectedEnqueuedLimboDocuments;
  224. }
  225. - (void)setExpectedEnqueuedLimboDocuments:(DocumentKeySet)docs {
  226. _expectedEnqueuedLimboDocuments = std::move(docs);
  227. }
  228. - (void)drainQueue {
  229. _workerQueue->EnqueueBlocking([] {});
  230. }
  231. - (const User &)currentUser {
  232. return _currentUser;
  233. }
  234. - (const DatabaseInfo &)databaseInfo {
  235. return _databaseInfo;
  236. }
  237. - (void)incrementSnapshotsInSyncEvents {
  238. _snapshotsInSyncEvents += 1;
  239. }
  240. - (void)resetSnapshotsInSyncEvents {
  241. _snapshotsInSyncEvents = 0;
  242. }
  243. - (void)incrementWaitForPendingWritesEvents {
  244. _waitForPendingWritesEvents += 1;
  245. }
  246. - (void)resetWaitForPendingWritesEvents {
  247. _waitForPendingWritesEvents = 0;
  248. }
  249. - (void)waitForPendingWrites {
  250. _syncEngine->RegisterPendingWritesCallback(
  251. [self](const Status &) { [self incrementWaitForPendingWritesEvents]; });
  252. }
  253. - (void)addSnapshotsInSyncListener {
  254. std::shared_ptr<EventListener<Empty>> eventListener = EventListener<Empty>::Create(
  255. [self](const StatusOr<Empty> &) { [self incrementSnapshotsInSyncEvents]; });
  256. _snapshotsInSyncListeners.push_back(eventListener);
  257. _eventManager->AddSnapshotsInSyncListener(eventListener);
  258. }
  259. - (void)removeSnapshotsInSyncListener {
  260. if (_snapshotsInSyncListeners.empty()) {
  261. HARD_FAIL("There must be a listener to unlisten to");
  262. } else {
  263. _eventManager->RemoveSnapshotsInSyncListener(_snapshotsInSyncListeners.back());
  264. _snapshotsInSyncListeners.pop_back();
  265. }
  266. }
  267. - (int)waitForPendingWritesEvents {
  268. return _waitForPendingWritesEvents;
  269. }
  270. - (int)snapshotsInSyncEvents {
  271. return _snapshotsInSyncEvents;
  272. }
  273. - (void)start {
  274. _workerQueue->EnqueueBlocking([&] {
  275. _localStore->Start();
  276. _remoteStore->Start();
  277. });
  278. }
  279. - (void)validateUsage {
  280. // We could relax this if we found a reason to.
  281. HARD_ASSERT(self.events.count == 0, "You must clear all pending events by calling"
  282. " capturedEventsSinceLastCall before calling shutdown.");
  283. }
  284. - (void)shutdown {
  285. _workerQueue->EnqueueBlocking([&] {
  286. _remoteStore->Shutdown();
  287. _persistence->Shutdown();
  288. });
  289. }
  290. - (void)validateNextWriteSent:(const Mutation &)expectedWrite {
  291. std::vector<Mutation> request = _datastore->NextSentWrite();
  292. // Make sure the write went through the pipe like we expected it to.
  293. HARD_ASSERT(request.size() == 1, "Only single mutation requests are supported at the moment");
  294. const Mutation &actualWrite = request[0];
  295. HARD_ASSERT(actualWrite == expectedWrite,
  296. "Mock datastore received write %s but first outstanding mutation was %s",
  297. actualWrite.ToString(), expectedWrite.ToString());
  298. LOG_DEBUG("A write was sent: %s", actualWrite.ToString());
  299. }
  300. - (int)sentWritesCount {
  301. return _datastore->WritesSent();
  302. }
  303. - (int)writeStreamRequestCount {
  304. return _datastore->write_stream_request_count();
  305. }
  306. - (int)watchStreamRequestCount {
  307. return _datastore->watch_stream_request_count();
  308. }
  309. - (void)disableNetwork {
  310. _workerQueue->EnqueueBlocking([&] {
  311. // Make sure to execute all writes that are currently queued. This allows us
  312. // to assert on the total number of requests sent before shutdown.
  313. _remoteStore->FillWritePipeline();
  314. _remoteStore->DisableNetwork();
  315. });
  316. }
  317. - (void)enableNetwork {
  318. _workerQueue->EnqueueBlocking([&] { _remoteStore->EnableNetwork(); });
  319. }
  320. - (void)runTimer:(TimerId)timerID {
  321. _workerQueue->RunScheduledOperationsUntil(timerID);
  322. }
  323. - (void)changeUser:(const User &)user {
  324. _currentUser = user;
  325. _workerQueue->EnqueueBlocking([&] { _syncEngine->HandleCredentialChange(user); });
  326. }
  327. - (FSTOutstandingWrite *)receiveWriteAckWithVersion:(const SnapshotVersion &)commitVersion
  328. mutationResults:(std::vector<MutationResult>)mutationResults {
  329. FSTOutstandingWrite *write = [self currentOutstandingWrites].firstObject;
  330. [[self currentOutstandingWrites] removeObjectAtIndex:0];
  331. [self validateNextWriteSent:write.write];
  332. _workerQueue->EnqueueBlocking(
  333. [&] { _datastore->AckWrite(commitVersion, std::move(mutationResults)); });
  334. return write;
  335. }
  336. - (FSTOutstandingWrite *)receiveWriteError:(int)errorCode
  337. userInfo:(NSDictionary<NSString *, id> *)userInfo
  338. keepInQueue:(BOOL)keepInQueue {
  339. Status error{static_cast<Error>(errorCode), MakeString([userInfo description])};
  340. FSTOutstandingWrite *write = [self currentOutstandingWrites].firstObject;
  341. [self validateNextWriteSent:write.write];
  342. // If this is a permanent error, the mutation is not expected to be sent again so we remove it
  343. // from currentOutstandingWrites.
  344. if (!keepInQueue) {
  345. [[self currentOutstandingWrites] removeObjectAtIndex:0];
  346. }
  347. LOG_DEBUG("Failing a write.");
  348. _workerQueue->EnqueueBlocking([&] { _datastore->FailWrite(error); });
  349. return write;
  350. }
  351. - (NSArray<FSTQueryEvent *> *)capturedEventsSinceLastCall {
  352. NSArray<FSTQueryEvent *> *result = [self.events copy];
  353. [self.events removeAllObjects];
  354. return result;
  355. }
  356. - (NSArray<NSString *> *)capturedAcknowledgedWritesSinceLastCall {
  357. NSArray<NSString *> *result = [self.acknowledgedDocs copy];
  358. [self.acknowledgedDocs removeAllObjects];
  359. return result;
  360. }
  361. - (NSArray<NSString *> *)capturedRejectedWritesSinceLastCall {
  362. NSArray<NSString *> *result = [self.rejectedDocs copy];
  363. [self.rejectedDocs removeAllObjects];
  364. return result;
  365. }
  366. - (TargetId)addUserListenerWithQuery:(Query)query {
  367. // TODO(dimond): Allow customizing listen options in spec tests
  368. // TODO(dimond): Change spec tests to verify isFromCache on snapshots
  369. ListenOptions options = ListenOptions::FromIncludeMetadataChanges(true);
  370. auto listener = QueryListener::Create(
  371. query, options, [self, query](const StatusOr<ViewSnapshot> &maybe_snapshot) {
  372. FSTQueryEvent *event = [[FSTQueryEvent alloc] init];
  373. event.query = query;
  374. if (maybe_snapshot.ok()) {
  375. [event setViewSnapshot:maybe_snapshot.ValueOrDie()];
  376. } else {
  377. event.error = MakeNSError(maybe_snapshot.status());
  378. }
  379. [self.events addObject:event];
  380. });
  381. _queryListeners[query] = listener;
  382. TargetId targetID;
  383. _workerQueue->EnqueueBlocking([&] { targetID = _eventManager->AddQueryListener(listener); });
  384. return targetID;
  385. }
  386. - (void)removeUserListenerWithQuery:(const Query &)query {
  387. auto found_iter = _queryListeners.find(query);
  388. if (found_iter != _queryListeners.end()) {
  389. std::shared_ptr<QueryListener> listener = found_iter->second;
  390. _queryListeners.erase(found_iter);
  391. _workerQueue->EnqueueBlocking([&] { _eventManager->RemoveQueryListener(listener); });
  392. }
  393. }
  394. - (void)loadBundleWithReader:(std::shared_ptr<BundleReader>)reader
  395. task:(std::shared_ptr<LoadBundleTask>)task {
  396. _workerQueue->EnqueueBlocking(
  397. [=] { _syncEngine->LoadBundle(std::move(reader), std::move(task)); });
  398. }
  399. - (void)writeUserMutation:(Mutation)mutation {
  400. FSTOutstandingWrite *write = [[FSTOutstandingWrite alloc] init];
  401. write.write = mutation;
  402. [[self currentOutstandingWrites] addObject:write];
  403. LOG_DEBUG("sending a user write.");
  404. _workerQueue->EnqueueBlocking([=] {
  405. _syncEngine->WriteMutations({mutation}, [self, write, mutation](Status error) {
  406. LOG_DEBUG("A callback was called with error: %s", error.error_message());
  407. write.done = YES;
  408. write.error = error.ToNSError();
  409. NSString *mutationKey = MakeNSString(mutation.key().ToString());
  410. if (!error.ok()) {
  411. [self.rejectedDocs addObject:mutationKey];
  412. } else {
  413. [self.acknowledgedDocs addObject:mutationKey];
  414. }
  415. });
  416. });
  417. }
  418. - (void)receiveWatchChange:(const WatchChange &)change
  419. snapshotVersion:(const SnapshotVersion &)snapshot {
  420. _workerQueue->EnqueueBlocking([&] { _datastore->WriteWatchChange(change, snapshot); });
  421. }
  422. - (void)receiveWatchStreamError:(int)errorCode userInfo:(NSDictionary<NSString *, id> *)userInfo {
  423. Status error{static_cast<Error>(errorCode), MakeString([userInfo description])};
  424. _workerQueue->EnqueueBlocking([&] {
  425. _datastore->FailWatchStream(error);
  426. // Unlike web, stream should re-open synchronously (if we have any listeners)
  427. if (!_queryListeners.empty()) {
  428. HARD_ASSERT(_datastore->IsWatchStreamOpen(), "Watch stream is open");
  429. }
  430. });
  431. }
  432. - (std::map<DocumentKey, TargetId>)activeLimboDocumentResolutions {
  433. return _syncEngine->GetActiveLimboDocumentResolutions();
  434. }
  435. - (std::vector<DocumentKey>)enqueuedLimboDocumentResolutions {
  436. return _syncEngine->GetEnqueuedLimboDocumentResolutions();
  437. }
  438. - (const std::unordered_map<TargetId, TargetData> &)activeTargets {
  439. return _datastore->ActiveTargets();
  440. }
  441. - (const ActiveTargetMap &)expectedActiveTargets {
  442. return _expectedActiveTargets;
  443. }
  444. - (void)setExpectedActiveTargets:(ActiveTargetMap)targets {
  445. _expectedActiveTargets = std::move(targets);
  446. }
  447. #pragma mark - Helper Methods
  448. - (NSMutableArray<FSTOutstandingWrite *> *)currentOutstandingWrites {
  449. NSMutableArray<FSTOutstandingWrite *> *writes = _outstandingWrites[_currentUser];
  450. if (!writes) {
  451. writes = [NSMutableArray array];
  452. _outstandingWrites[_currentUser] = writes;
  453. }
  454. return writes;
  455. }
  456. @end
  457. NS_ASSUME_NONNULL_END