Files
firebase-ios-sdk/Firestore/Example/Tests/Local/FSTLocalStoreTests.mm
T

1165 lines
50 KiB
Plaintext
Raw Normal View History

2017-10-03 08:55:22 -07:00
/*
* Copyright 2017 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import "Firestore/Source/Local/FSTLocalStore.h"
2017-10-03 08:55:22 -07:00
#import <FirebaseFirestore/FIRTimestamp.h>
2017-10-03 08:55:22 -07:00
#import <XCTest/XCTest.h>
2019-02-07 22:03:17 -05:00
#include <utility>
#include <vector>
2019-03-06 14:51:30 -08:00
#import "Firestore/Source/API/FIRFieldValue+Internal.h"
#import "Firestore/Source/Core/FSTQuery.h"
#import "Firestore/Source/Local/FSTLocalWriteResult.h"
#import "Firestore/Source/Local/FSTPersistence.h"
#import "Firestore/Source/Local/FSTQueryData.h"
#import "Firestore/Source/Model/FSTDocument.h"
#import "Firestore/Source/Model/FSTMutation.h"
#import "Firestore/Source/Model/FSTMutationBatch.h"
#import "Firestore/Source/Util/FSTClasses.h"
2017-10-03 08:55:22 -07:00
#import "Firestore/Example/Tests/Local/FSTLocalStoreTests.h"
#import "Firestore/Example/Tests/Util/FSTHelpers.h"
#import "Firestore/third_party/Immutable/Tests/FSTImmutableSortedDictionary+Testing.h"
#import "Firestore/third_party/Immutable/Tests/FSTImmutableSortedSet+Testing.h"
2017-10-03 08:55:22 -07:00
#include "Firestore/core/src/firebase/firestore/auth/user.h"
#include "Firestore/core/src/firebase/firestore/model/document_map.h"
2019-03-25 11:04:21 -07:00
#include "Firestore/core/src/firebase/firestore/model/document_set.h"
#include "Firestore/core/src/firebase/firestore/remote/remote_event.h"
2019-01-23 17:26:49 -05:00
#include "Firestore/core/src/firebase/firestore/remote/watch_change.h"
#include "Firestore/core/src/firebase/firestore/util/status.h"
#include "Firestore/core/test/firebase/firestore/testutil/testutil.h"
namespace testutil = firebase::firestore::testutil;
using firebase::firestore::auth::User;
using firebase::firestore::model::DocumentKey;
using firebase::firestore::model::DocumentKeySet;
using firebase::firestore::model::ListenSequenceNumber;
using firebase::firestore::model::DocumentMap;
using firebase::firestore::model::MaybeDocumentMap;
using firebase::firestore::model::SnapshotVersion;
2018-08-15 15:56:45 -07:00
using firebase::firestore::model::TargetId;
2019-01-29 18:55:25 -05:00
using firebase::firestore::remote::RemoteEvent;
using firebase::firestore::remote::TestTargetMetadataProvider;
using firebase::firestore::remote::WatchChangeAggregator;
2019-01-23 17:26:49 -05:00
using firebase::firestore::remote::WatchTargetChange;
using firebase::firestore::remote::WatchTargetChangeState;
using firebase::firestore::util::Status;
static NSArray<FSTDocument *> *docMapToArray(const DocumentMap &docs) {
NSMutableArray<FSTDocument *> *result = [NSMutableArray array];
for (const auto &kv : docs.underlying_map()) {
[result addObject:static_cast<FSTDocument *>(kv.second)];
}
return result;
}
2017-10-03 08:55:22 -07:00
NS_ASSUME_NONNULL_BEGIN
@interface FSTLocalStoreTests ()
@property(nonatomic, strong, readwrite) id<FSTPersistence> localStorePersistence;
@property(nonatomic, strong, readwrite) FSTLocalStore *localStore;
@property(nonatomic, strong, readonly) NSMutableArray<FSTMutationBatch *> *batches;
2018-08-15 15:56:45 -07:00
@property(nonatomic, assign, readwrite) TargetId lastTargetID;
2017-10-03 08:55:22 -07:00
@end
@implementation FSTLocalStoreTests {
MaybeDocumentMap _lastChanges;
}
2017-10-03 08:55:22 -07:00
- (void)setUp {
[super setUp];
if ([self isTestBaseClass]) {
return;
}
id<FSTPersistence> persistence = [self persistence];
self.localStorePersistence = persistence;
self.localStore = [[FSTLocalStore alloc] initWithPersistence:persistence
initialUser:User::Unauthenticated()];
2017-10-03 08:55:22 -07:00
[self.localStore start];
_batches = [NSMutableArray array];
_lastTargetID = 0;
}
- (void)tearDown {
[self.localStorePersistence shutdown];
[super tearDown];
}
- (id<FSTPersistence>)persistence {
@throw FSTAbstractMethodException(); // NOLINT
}
2018-07-27 13:58:11 -07:00
- (BOOL)gcIsEager {
@throw FSTAbstractMethodException(); // NOLINT
}
2017-10-03 08:55:22 -07:00
/**
* Xcode will run tests from any class that extends XCTestCase, but this doesn't work for
* FSTLocalStoreTests since it is incomplete without the implementations supplied by its
* subclasses.
*/
- (BOOL)isTestBaseClass {
return [self class] == [FSTLocalStoreTests class];
}
- (void)writeMutation:(FSTMutation *)mutation {
2019-02-07 22:03:17 -05:00
[self writeMutations:{mutation}];
2017-10-03 08:55:22 -07:00
}
2019-02-07 22:03:17 -05:00
- (void)writeMutations:(std::vector<FSTMutation *> &&)mutations {
auto mutationsCopy = mutations;
FSTLocalWriteResult *result = [self.localStore locallyWriteMutations:std::move(mutationsCopy)];
2017-10-03 08:55:22 -07:00
XCTAssertNotNil(result);
[self.batches addObject:[[FSTMutationBatch alloc] initWithBatchID:result.batchID
localWriteTime:[FIRTimestamp timestamp]
2019-03-06 14:51:30 -08:00
baseMutations:{}
2019-02-07 22:03:17 -05:00
mutations:std::move(mutations)]];
_lastChanges = result.changes;
2017-10-03 08:55:22 -07:00
}
2019-01-29 18:55:25 -05:00
- (void)applyRemoteEvent:(const RemoteEvent &)event {
_lastChanges = [self.localStore applyRemoteEvent:event];
2017-10-03 08:55:22 -07:00
}
- (void)notifyLocalViewChanges:(FSTLocalViewChanges *)changes {
[self.localStore notifyLocalViewChanges:@[ changes ]];
}
2019-03-06 14:51:30 -08:00
- (void)acknowledgeMutationWithVersion:(FSTTestSnapshotVersion)documentVersion
transformResult:(id _Nullable)transformResult {
2017-10-03 08:55:22 -07:00
FSTMutationBatch *batch = [self.batches firstObject];
[self.batches removeObjectAtIndex:0];
2019-02-07 22:03:17 -05:00
XCTAssertEqual(batch.mutations.size(), 1, @"Acknowledging more than one mutation not supported.");
SnapshotVersion version = testutil::Version(documentVersion);
2019-03-06 14:51:30 -08:00
FSTMutationResult *mutationResult = [[FSTMutationResult alloc]
initWithVersion:version
transformResults:transformResult != nil ? @[ FSTTestFieldValue(transformResult) ] : nil];
2017-10-03 08:55:22 -07:00
FSTMutationBatchResult *result = [FSTMutationBatchResult resultWithBatch:batch
commitVersion:version
mutationResults:{mutationResult}
2017-10-03 08:55:22 -07:00
streamToken:nil];
_lastChanges = [self.localStore acknowledgeBatchWithResult:result];
2017-10-03 08:55:22 -07:00
}
2019-03-06 14:51:30 -08:00
- (void)acknowledgeMutationWithVersion:(FSTTestSnapshotVersion)documentVersion {
[self acknowledgeMutationWithVersion:documentVersion transformResult:nil];
}
2017-10-03 08:55:22 -07:00
- (void)rejectMutation {
FSTMutationBatch *batch = [self.batches firstObject];
[self.batches removeObjectAtIndex:0];
_lastChanges = [self.localStore rejectBatchID:batch.batchID];
2017-10-03 08:55:22 -07:00
}
2018-08-15 15:56:45 -07:00
- (TargetId)allocateQuery:(FSTQuery *)query {
2017-10-03 08:55:22 -07:00
FSTQueryData *queryData = [self.localStore allocateQuery:query];
self.lastTargetID = queryData.targetID;
2018-04-16 12:18:35 -07:00
return queryData.targetID;
2017-10-03 08:55:22 -07:00
}
/** Asserts that the last target ID is the given number. */
#define FSTAssertTargetID(targetID) \
do { \
XCTAssertEqual(self.lastTargetID, targetID); \
} while (0)
/** Asserts that a the lastChanges contain the docs in the given array. */
#define FSTAssertChanged(documents) \
do { \
NSArray<FSTMaybeDocument *> *expected = (documents); \
XCTAssertEqual(_lastChanges.size(), expected.count); \
NSEnumerator<FSTMaybeDocument *> *enumerator = expected.objectEnumerator; \
for (const auto &kv : _lastChanges) { \
FSTMaybeDocument *value = kv.second; \
XCTAssertEqualObjects(value, [enumerator nextObject]); \
} \
_lastChanges = MaybeDocumentMap{}; \
2017-10-03 08:55:22 -07:00
} while (0)
/** Asserts that the given keys were removed. */
#define FSTAssertRemoved(keyPaths) \
do { \
XCTAssertEqual(_lastChanges.size(), keyPaths.count); \
NSEnumerator<NSString *> *keyPathEnumerator = keyPaths.objectEnumerator; \
for (const auto &kv : _lastChanges) { \
const DocumentKey &actualKey = kv.first; \
FSTMaybeDocument *value = kv.second; \
DocumentKey expectedKey = FSTTestDocKey([keyPathEnumerator nextObject]); \
XCTAssertEqual(actualKey, expectedKey); \
XCTAssertTrue([value isKindOfClass:[FSTDeletedDocument class]]); \
} \
_lastChanges = MaybeDocumentMap{}; \
2017-10-03 08:55:22 -07:00
} while (0)
/** Asserts that the given local store contains the given document. */
#define FSTAssertContains(document) \
do { \
FSTMaybeDocument *expected = (document); \
FSTMaybeDocument *actual = [self.localStore readDocument:expected.key]; \
XCTAssertEqualObjects(actual, expected); \
} while (0)
/** Asserts that the given local store does not contain the given document. */
2017-12-19 13:47:04 -05:00
#define FSTAssertNotContains(keyPathString) \
do { \
DocumentKey key = FSTTestDocKey(keyPathString); \
2017-12-19 13:47:04 -05:00
FSTMaybeDocument *actual = [self.localStore readDocument:key]; \
XCTAssertNil(actual); \
2017-10-03 08:55:22 -07:00
} while (0)
- (void)testMutationBatchKeys {
if ([self isTestBaseClass]) return;
2019-03-06 14:51:30 -08:00
FSTMutation *base = FSTTestSetMutation(@"foo/ignore", @{@"foo" : @"bar"});
2017-10-03 08:55:22 -07:00
FSTMutation *set1 = FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"});
FSTMutation *set2 = FSTTestSetMutation(@"bar/baz", @{@"bar" : @"baz"});
FSTMutationBatch *batch = [[FSTMutationBatch alloc] initWithBatchID:1
localWriteTime:[FIRTimestamp timestamp]
2019-03-06 14:51:30 -08:00
baseMutations:{base}
2019-02-07 22:03:17 -05:00
mutations:{set1, set2}];
DocumentKeySet keys = [batch keys];
XCTAssertEqual(keys.size(), 2u);
2017-10-03 08:55:22 -07:00
}
- (void)testHandlesSetMutation {
if ([self isTestBaseClass]) return;
[self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations) ]);
FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations));
2017-10-03 08:55:22 -07:00
[self acknowledgeMutationWithVersion:0];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateCommittedMutations) ]);
2018-07-27 13:58:11 -07:00
if ([self gcIsEager]) {
// Nothing is pinning this anymore, as it has been acknowledged and there are no targets active.
FSTAssertNotContains(@"foo/bar");
} else {
2018-11-01 09:44:30 -07:00
FSTAssertContains(
FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateCommittedMutations));
2018-07-27 13:58:11 -07:00
}
2017-10-03 08:55:22 -07:00
}
- (void)testHandlesSetMutationThenDocument {
if ([self isTestBaseClass]) return;
[self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations) ]);
FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations));
2017-10-03 08:55:22 -07:00
2018-04-16 12:18:35 -07:00
FSTQuery *query = FSTTestQuery("foo");
2018-08-15 15:56:45 -07:00
TargetId targetID = [self allocateQuery:query];
2018-04-16 12:18:35 -07:00
2018-11-01 09:44:30 -07:00
[self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 2, @{@"it" : @"changed"},
FSTDocumentStateSynced),
2019-01-23 17:26:49 -05:00
{targetID}, {})];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations) ]);
FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations));
2017-10-03 08:55:22 -07:00
}
- (void)testHandlesAckThenRejectThenRemoteEvent {
if ([self isTestBaseClass]) return;
// Start a query that requires acks to be held.
FSTQuery *query = FSTTestQuery("foo");
2018-08-15 15:56:45 -07:00
TargetId targetID = [self allocateQuery:query];
2017-10-03 08:55:22 -07:00
[self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations) ]);
FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations));
2017-10-03 08:55:22 -07:00
// The last seen version is zero, so this ack must be held.
[self acknowledgeMutationWithVersion:1];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, FSTDocumentStateCommittedMutations) ]);
// Under eager GC, there is no longer a reference for the document, and it should be
// deleted.
if ([self gcIsEager]) {
FSTAssertNotContains(@"foo/bar");
} else {
FSTAssertContains(
FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, FSTDocumentStateCommittedMutations));
}
2017-10-03 08:55:22 -07:00
[self writeMutation:FSTTestSetMutation(@"bar/baz", @{@"bar" : @"baz"})];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(
@[ FSTTestDoc("bar/baz", 0, @{@"bar" : @"baz"}, FSTDocumentStateLocalMutations) ]);
FSTAssertContains(FSTTestDoc("bar/baz", 0, @{@"bar" : @"baz"}, FSTDocumentStateLocalMutations));
2017-10-03 08:55:22 -07:00
[self rejectMutation];
FSTAssertRemoved(@[ @"bar/baz" ]);
FSTAssertNotContains(@"bar/baz");
2018-11-01 09:44:30 -07:00
[self applyRemoteEvent:FSTTestAddedRemoteEvent(FSTTestDoc("foo/bar", 2, @{@"it" : @"changed"},
FSTDocumentStateSynced),
2019-01-23 17:26:49 -05:00
{targetID})];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 2, @{@"it" : @"changed"}, FSTDocumentStateSynced) ]);
FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"it" : @"changed"}, FSTDocumentStateSynced));
2017-10-03 08:55:22 -07:00
FSTAssertNotContains(@"bar/baz");
}
- (void)testHandlesDeletedDocumentThenSetMutationThenAck {
if ([self isTestBaseClass]) return;
2018-04-16 12:18:35 -07:00
FSTQuery *query = FSTTestQuery("foo");
2018-08-15 15:56:45 -07:00
TargetId targetID = [self allocateQuery:query];
2018-04-16 12:18:35 -07:00
2019-01-23 17:26:49 -05:00
[self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDeletedDoc("foo/bar", 2, NO), {targetID},
{})];
2017-10-03 08:55:22 -07:00
FSTAssertRemoved(@[ @"foo/bar" ]);
2018-07-27 13:58:11 -07:00
// Under eager GC, there is no longer a reference for the document, and it should be
// deleted.
if (![self gcIsEager]) {
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDeletedDoc("foo/bar", 2, NO));
2018-07-27 13:58:11 -07:00
} else {
FSTAssertNotContains(@"foo/bar");
}
2017-10-03 08:55:22 -07:00
[self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations) ]);
FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations));
2018-04-16 12:18:35 -07:00
// Can now remove the target, since we have a mutation pinning the document
[self.localStore releaseQuery:query];
2018-07-27 13:58:11 -07:00
// Verify we didn't lose anything
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations));
2017-10-03 08:55:22 -07:00
[self acknowledgeMutationWithVersion:3];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 3, @{@"foo" : @"bar"}, FSTDocumentStateCommittedMutations) ]);
2018-07-27 13:58:11 -07:00
// It has been acknowledged, and should no longer be retained as there is no target and mutation
if ([self gcIsEager]) {
FSTAssertNotContains(@"foo/bar");
}
2017-10-03 08:55:22 -07:00
}
- (void)testHandlesSetMutationThenDeletedDocument {
if ([self isTestBaseClass]) return;
2018-04-16 12:18:35 -07:00
FSTQuery *query = FSTTestQuery("foo");
2018-08-15 15:56:45 -07:00
TargetId targetID = [self allocateQuery:query];
2018-04-16 12:18:35 -07:00
2017-10-03 08:55:22 -07:00
[self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations) ]);
2017-10-03 08:55:22 -07:00
2019-01-23 17:26:49 -05:00
[self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDeletedDoc("foo/bar", 2, NO), {targetID},
{})];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations) ]);
FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations));
2017-10-03 08:55:22 -07:00
}
- (void)testHandlesDocumentThenSetMutationThenAckThenDocument {
if ([self isTestBaseClass]) return;
2018-04-16 12:18:35 -07:00
// Start a query that requires acks to be held.
FSTQuery *query = FSTTestQuery("foo");
2018-08-15 15:56:45 -07:00
TargetId targetID = [self allocateQuery:query];
2018-04-16 12:18:35 -07:00
2018-11-01 09:44:30 -07:00
[self applyRemoteEvent:FSTTestAddedRemoteEvent(
FSTTestDoc("foo/bar", 2, @{@"it" : @"base"}, FSTDocumentStateSynced),
2019-01-23 17:26:49 -05:00
{targetID})];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 2, @{@"it" : @"base"}, FSTDocumentStateSynced) ]);
FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"it" : @"base"}, FSTDocumentStateSynced));
2017-10-03 08:55:22 -07:00
[self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations) ]);
FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations));
2017-10-03 08:55:22 -07:00
[self acknowledgeMutationWithVersion:3];
2018-04-16 12:18:35 -07:00
// we haven't seen the remote event yet, so the write is still held.
2018-11-01 09:44:30 -07:00
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 3, @{@"foo" : @"bar"}, FSTDocumentStateCommittedMutations) ]);
FSTAssertContains(
FSTTestDoc("foo/bar", 3, @{@"foo" : @"bar"}, FSTDocumentStateCommittedMutations));
2017-10-03 08:55:22 -07:00
2018-11-01 09:44:30 -07:00
[self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 3, @{@"it" : @"changed"},
FSTDocumentStateSynced),
2019-01-23 17:26:49 -05:00
{targetID}, {})];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 3, @{@"it" : @"changed"}, FSTDocumentStateSynced) ]);
FSTAssertContains(FSTTestDoc("foo/bar", 3, @{@"it" : @"changed"}, FSTDocumentStateSynced));
2017-10-03 08:55:22 -07:00
}
- (void)testHandlesPatchWithoutPriorDocument {
if ([self isTestBaseClass]) return;
[self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})];
2017-10-03 08:55:22 -07:00
FSTAssertRemoved(@[ @"foo/bar" ]);
FSTAssertNotContains(@"foo/bar");
[self acknowledgeMutationWithVersion:1];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(@[ FSTTestUnknownDoc("foo/bar", 1) ]);
if ([self gcIsEager]) {
FSTAssertNotContains(@"foo/bar");
} else {
FSTAssertContains(FSTTestUnknownDoc("foo/bar", 1));
}
2017-10-03 08:55:22 -07:00
}
- (void)testHandlesPatchMutationThenDocumentThenAck {
if ([self isTestBaseClass]) return;
[self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})];
2017-10-03 08:55:22 -07:00
FSTAssertRemoved(@[ @"foo/bar" ]);
FSTAssertNotContains(@"foo/bar");
2018-04-16 12:18:35 -07:00
FSTQuery *query = FSTTestQuery("foo");
2018-08-15 15:56:45 -07:00
TargetId targetID = [self allocateQuery:query];
2018-04-16 12:18:35 -07:00
2018-11-01 09:44:30 -07:00
[self applyRemoteEvent:FSTTestAddedRemoteEvent(
FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, FSTDocumentStateSynced),
2019-01-23 17:26:49 -05:00
{targetID})];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar", @"it" : @"base"},
FSTDocumentStateLocalMutations) ]);
FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar", @"it" : @"base"},
FSTDocumentStateLocalMutations));
2017-10-03 08:55:22 -07:00
[self acknowledgeMutationWithVersion:2];
2018-04-16 12:18:35 -07:00
// We still haven't seen the remote events for the patch, so the local changes remain, and there
// are no changes
2018-11-01 09:44:30 -07:00
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar", @"it" : @"base"},
FSTDocumentStateCommittedMutations) ]);
FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar", @"it" : @"base"},
FSTDocumentStateCommittedMutations));
2018-04-16 12:18:35 -07:00
[self applyRemoteEvent:FSTTestUpdateRemoteEvent(
2018-11-01 09:44:30 -07:00
FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar", @"it" : @"base"},
FSTDocumentStateSynced),
2019-01-23 17:26:49 -05:00
{targetID}, {})];
2018-04-16 12:18:35 -07:00
2018-11-01 09:44:30 -07:00
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar", @"it" : @"base"}, FSTDocumentStateSynced) ]);
FSTAssertContains(
FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar", @"it" : @"base"}, FSTDocumentStateSynced));
2017-10-03 08:55:22 -07:00
}
- (void)testHandlesPatchMutationThenAckThenDocument {
if ([self isTestBaseClass]) return;
[self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})];
2017-10-03 08:55:22 -07:00
FSTAssertRemoved(@[ @"foo/bar" ]);
FSTAssertNotContains(@"foo/bar");
[self acknowledgeMutationWithVersion:1];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(@[ FSTTestUnknownDoc("foo/bar", 1) ]);
// There's no target pinning the doc, and we've ack'd the mutation.
if ([self gcIsEager]) {
FSTAssertNotContains(@"foo/bar");
} else {
FSTAssertContains(FSTTestUnknownDoc("foo/bar", 1));
}
2017-10-03 08:55:22 -07:00
2018-04-16 12:18:35 -07:00
FSTQuery *query = FSTTestQuery("foo");
2018-08-15 15:56:45 -07:00
TargetId targetID = [self allocateQuery:query];
2018-04-16 12:18:35 -07:00
2018-11-01 09:44:30 -07:00
[self applyRemoteEvent:FSTTestUpdateRemoteEvent(
FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, FSTDocumentStateSynced),
2019-01-23 17:26:49 -05:00
{targetID}, {})];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, FSTDocumentStateSynced) ]);
FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, FSTDocumentStateSynced));
2017-10-03 08:55:22 -07:00
}
- (void)testHandlesDeleteMutationThenAck {
if ([self isTestBaseClass]) return;
[self writeMutation:FSTTestDeleteMutation(@"foo/bar")];
FSTAssertRemoved(@[ @"foo/bar" ]);
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0, NO));
2017-10-03 08:55:22 -07:00
[self acknowledgeMutationWithVersion:1];
FSTAssertRemoved(@[ @"foo/bar" ]);
2018-07-27 13:58:11 -07:00
// There's no target pinning the doc, and we've ack'd the mutation.
if ([self gcIsEager]) {
FSTAssertNotContains(@"foo/bar");
}
2017-10-03 08:55:22 -07:00
}
- (void)testHandlesDocumentThenDeleteMutationThenAck {
if ([self isTestBaseClass]) return;
2018-04-16 12:18:35 -07:00
FSTQuery *query = FSTTestQuery("foo");
2018-08-15 15:56:45 -07:00
TargetId targetID = [self allocateQuery:query];
2018-04-16 12:18:35 -07:00
2018-11-01 09:44:30 -07:00
[self applyRemoteEvent:FSTTestUpdateRemoteEvent(
FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, FSTDocumentStateSynced),
2019-01-23 17:26:49 -05:00
{targetID}, {})];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, FSTDocumentStateSynced) ]);
FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, FSTDocumentStateSynced));
2017-10-03 08:55:22 -07:00
[self writeMutation:FSTTestDeleteMutation(@"foo/bar")];
FSTAssertRemoved(@[ @"foo/bar" ]);
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0, NO));
2017-10-03 08:55:22 -07:00
2018-04-16 12:18:35 -07:00
// Remove the target so only the mutation is pinning the document
[self.localStore releaseQuery:query];
2017-10-03 08:55:22 -07:00
[self acknowledgeMutationWithVersion:2];
FSTAssertRemoved(@[ @"foo/bar" ]);
2018-07-27 13:58:11 -07:00
if ([self gcIsEager]) {
// Neither the target nor the mutation pin the document, it should be gone.
FSTAssertNotContains(@"foo/bar");
}
2017-10-03 08:55:22 -07:00
}
- (void)testHandlesDeleteMutationThenDocumentThenAck {
if ([self isTestBaseClass]) return;
2018-04-16 12:18:35 -07:00
FSTQuery *query = FSTTestQuery("foo");
2018-08-15 15:56:45 -07:00
TargetId targetID = [self allocateQuery:query];
2018-04-16 12:18:35 -07:00
2017-10-03 08:55:22 -07:00
[self writeMutation:FSTTestDeleteMutation(@"foo/bar")];
FSTAssertRemoved(@[ @"foo/bar" ]);
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0, NO));
2017-10-03 08:55:22 -07:00
2018-07-27 13:58:11 -07:00
// Add the document to a target so it will remain in persistence even when ack'd
2018-11-01 09:44:30 -07:00
[self applyRemoteEvent:FSTTestUpdateRemoteEvent(
FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, FSTDocumentStateSynced),
2019-01-23 17:26:49 -05:00
{targetID}, {})];
2017-10-03 08:55:22 -07:00
FSTAssertRemoved(@[ @"foo/bar" ]);
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0, NO));
2017-10-03 08:55:22 -07:00
2018-04-16 12:18:35 -07:00
// Don't need to keep it pinned anymore
[self.localStore releaseQuery:query];
2017-10-03 08:55:22 -07:00
[self acknowledgeMutationWithVersion:2];
FSTAssertRemoved(@[ @"foo/bar" ]);
2018-07-27 13:58:11 -07:00
if ([self gcIsEager]) {
// The doc is not pinned in a target and we've acknowledged the mutation. It shouldn't exist
// anymore.
FSTAssertNotContains(@"foo/bar");
}
2017-10-03 08:55:22 -07:00
}
- (void)testHandlesDocumentThenDeletedDocumentThenDocument {
if ([self isTestBaseClass]) return;
2018-04-16 12:18:35 -07:00
FSTQuery *query = FSTTestQuery("foo");
2018-08-15 15:56:45 -07:00
TargetId targetID = [self allocateQuery:query];
2018-04-16 12:18:35 -07:00
2018-11-01 09:44:30 -07:00
[self applyRemoteEvent:FSTTestUpdateRemoteEvent(
FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, FSTDocumentStateSynced),
2019-01-23 17:26:49 -05:00
{targetID}, {})];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, FSTDocumentStateSynced) ]);
FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, FSTDocumentStateSynced));
2017-10-03 08:55:22 -07:00
2019-01-23 17:26:49 -05:00
[self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDeletedDoc("foo/bar", 2, NO), {targetID},
{})];
2017-10-03 08:55:22 -07:00
FSTAssertRemoved(@[ @"foo/bar" ]);
2018-07-27 13:58:11 -07:00
if (![self gcIsEager]) {
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDeletedDoc("foo/bar", 2, NO));
2018-07-27 13:58:11 -07:00
}
2017-10-03 08:55:22 -07:00
2018-11-01 09:44:30 -07:00
[self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 3, @{@"it" : @"changed"},
FSTDocumentStateSynced),
2019-01-23 17:26:49 -05:00
{targetID}, {})];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 3, @{@"it" : @"changed"}, FSTDocumentStateSynced) ]);
FSTAssertContains(FSTTestDoc("foo/bar", 3, @{@"it" : @"changed"}, FSTDocumentStateSynced));
2017-10-03 08:55:22 -07:00
}
- (void)testHandlesSetMutationThenPatchMutationThenDocumentThenAckThenAck {
if ([self isTestBaseClass]) return;
[self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"old"})];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"old"}, FSTDocumentStateLocalMutations) ]);
FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"old"}, FSTDocumentStateLocalMutations));
2017-10-03 08:55:22 -07:00
[self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations) ]);
FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations));
2017-10-03 08:55:22 -07:00
2018-04-16 12:18:35 -07:00
FSTQuery *query = FSTTestQuery("foo");
2018-08-15 15:56:45 -07:00
TargetId targetID = [self allocateQuery:query];
2018-04-16 12:18:35 -07:00
2018-11-01 09:44:30 -07:00
[self applyRemoteEvent:FSTTestUpdateRemoteEvent(
FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, FSTDocumentStateSynced),
2019-01-23 17:26:49 -05:00
{targetID}, {})];
2018-11-01 09:44:30 -07:00
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations) ]);
FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations));
2017-10-03 08:55:22 -07:00
2018-04-16 12:18:35 -07:00
[self.localStore releaseQuery:query];
2017-10-03 08:55:22 -07:00
[self acknowledgeMutationWithVersion:2]; // delete mutation
2018-11-01 09:44:30 -07:00
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations) ]);
FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations));
2017-10-03 08:55:22 -07:00
[self acknowledgeMutationWithVersion:3]; // patch mutation
2018-11-01 09:44:30 -07:00
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 3, @{@"foo" : @"bar"}, FSTDocumentStateCommittedMutations) ]);
2018-07-27 13:58:11 -07:00
if ([self gcIsEager]) {
// we've ack'd all of the mutations, nothing is keeping this pinned anymore
FSTAssertNotContains(@"foo/bar");
2018-11-01 09:44:30 -07:00
} else {
FSTAssertContains(
FSTTestDoc("foo/bar", 3, @{@"foo" : @"bar"}, FSTDocumentStateCommittedMutations));
2018-07-27 13:58:11 -07:00
}
2017-10-03 08:55:22 -07:00
}
- (void)testHandlesSetMutationAndPatchMutationTogether {
if ([self isTestBaseClass]) return;
2019-02-07 22:03:17 -05:00
[self writeMutations:{
2017-10-03 08:55:22 -07:00
FSTTestSetMutation(@"foo/bar", @{@"foo" : @"old"}),
2019-02-07 22:03:17 -05:00
FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})
}];
2017-10-03 08:55:22 -07:00
2018-11-01 09:44:30 -07:00
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations) ]);
FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations));
2017-10-03 08:55:22 -07:00
}
- (void)testHandlesSetMutationThenPatchMutationThenReject {
if ([self isTestBaseClass]) return;
2018-07-27 13:58:11 -07:00
if (![self gcIsEager]) return;
2017-10-03 08:55:22 -07:00
[self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"old"})];
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"old"}, FSTDocumentStateLocalMutations));
2017-10-03 08:55:22 -07:00
[self acknowledgeMutationWithVersion:1];
2018-07-27 13:58:11 -07:00
FSTAssertNotContains(@"foo/bar");
2017-10-03 08:55:22 -07:00
[self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})];
2018-07-27 13:58:11 -07:00
// A blind patch is not visible in the cache
FSTAssertNotContains(@"foo/bar");
2017-10-03 08:55:22 -07:00
[self rejectMutation];
2018-07-27 13:58:11 -07:00
FSTAssertNotContains(@"foo/bar");
2017-10-03 08:55:22 -07:00
}
- (void)testHandlesSetMutationsAndPatchMutationOfJustOneTogether {
if ([self isTestBaseClass]) return;
2019-02-07 22:03:17 -05:00
[self writeMutations:{
2017-10-03 08:55:22 -07:00
FSTTestSetMutation(@"foo/bar", @{@"foo" : @"old"}),
2019-02-07 22:03:17 -05:00
FSTTestSetMutation(@"bar/baz", @{@"bar" : @"baz"}),
FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})
}];
2017-10-03 08:55:22 -07:00
FSTAssertChanged((@[
2018-11-01 09:44:30 -07:00
FSTTestDoc("bar/baz", 0, @{@"bar" : @"baz"}, FSTDocumentStateLocalMutations),
FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations)
2017-10-03 08:55:22 -07:00
]));
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations));
FSTAssertContains(FSTTestDoc("bar/baz", 0, @{@"bar" : @"baz"}, FSTDocumentStateLocalMutations));
2017-10-03 08:55:22 -07:00
}
- (void)testHandlesDeleteMutationThenPatchMutationThenAckThenAck {
if ([self isTestBaseClass]) return;
[self writeMutation:FSTTestDeleteMutation(@"foo/bar")];
FSTAssertRemoved(@[ @"foo/bar" ]);
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0, NO));
2017-10-03 08:55:22 -07:00
[self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})];
2017-10-03 08:55:22 -07:00
FSTAssertRemoved(@[ @"foo/bar" ]);
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDeletedDoc("foo/bar", 0, NO));
2017-10-03 08:55:22 -07:00
[self acknowledgeMutationWithVersion:2]; // delete mutation
FSTAssertRemoved(@[ @"foo/bar" ]);
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDeletedDoc("foo/bar", 2, YES));
2017-10-03 08:55:22 -07:00
[self acknowledgeMutationWithVersion:3]; // patch mutation
2018-11-01 09:44:30 -07:00
FSTAssertChanged(@[ FSTTestUnknownDoc("foo/bar", 3) ]);
2018-07-27 13:58:11 -07:00
if ([self gcIsEager]) {
// There are no more pending mutations, the doc has been dropped
FSTAssertNotContains(@"foo/bar");
2018-11-01 09:44:30 -07:00
} else {
FSTAssertContains(FSTTestUnknownDoc("foo/bar", 3));
2018-07-27 13:58:11 -07:00
}
2017-10-03 08:55:22 -07:00
}
- (void)testCollectsGarbageAfterChangeBatchWithNoTargetIDs {
if ([self isTestBaseClass]) return;
2018-07-27 13:58:11 -07:00
if (![self gcIsEager]) return;
2017-10-03 08:55:22 -07:00
2018-11-01 09:44:30 -07:00
[self applyRemoteEvent:FSTTestUpdateRemoteEventWithLimboTargets(
2019-01-23 17:26:49 -05:00
FSTTestDeletedDoc("foo/bar", 2, NO), {}, {}, {1})];
2017-10-03 08:55:22 -07:00
FSTAssertNotContains(@"foo/bar");
2018-07-27 13:58:11 -07:00
[self applyRemoteEvent:FSTTestUpdateRemoteEventWithLimboTargets(
2018-11-01 09:44:30 -07:00
FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, FSTDocumentStateSynced),
2019-01-23 17:26:49 -05:00
{}, {}, {1})];
2017-10-03 08:55:22 -07:00
FSTAssertNotContains(@"foo/bar");
}
- (void)testCollectsGarbageAfterChangeBatch {
if ([self isTestBaseClass]) return;
2018-07-27 13:58:11 -07:00
if (![self gcIsEager]) return;
2017-10-03 08:55:22 -07:00
FSTQuery *query = FSTTestQuery("foo");
2018-08-15 15:56:45 -07:00
TargetId targetID = [self allocateQuery:query];
2017-10-03 08:55:22 -07:00
2018-11-01 09:44:30 -07:00
[self applyRemoteEvent:FSTTestAddedRemoteEvent(
FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, FSTDocumentStateSynced),
2019-01-23 17:26:49 -05:00
{targetID})];
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, FSTDocumentStateSynced));
2017-10-03 08:55:22 -07:00
2018-11-01 09:44:30 -07:00
[self applyRemoteEvent:FSTTestUpdateRemoteEvent(
FSTTestDoc("foo/bar", 2, @{@"foo" : @"baz"}, FSTDocumentStateSynced),
2019-01-23 17:26:49 -05:00
{}, {targetID})];
2017-10-03 08:55:22 -07:00
FSTAssertNotContains(@"foo/bar");
}
- (void)testCollectsGarbageAfterAcknowledgedMutation {
if ([self isTestBaseClass]) return;
2018-07-27 13:58:11 -07:00
if (![self gcIsEager]) return;
2017-10-03 08:55:22 -07:00
2018-04-16 12:18:35 -07:00
FSTQuery *query = FSTTestQuery("foo");
2018-08-15 15:56:45 -07:00
TargetId targetID = [self allocateQuery:query];
2018-04-16 12:18:35 -07:00
2018-11-01 09:44:30 -07:00
[self applyRemoteEvent:FSTTestUpdateRemoteEvent(
FSTTestDoc("foo/bar", 0, @{@"foo" : @"old"}, FSTDocumentStateSynced),
2019-01-23 17:26:49 -05:00
{targetID}, {})];
[self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})];
2018-04-16 12:18:35 -07:00
// Release the query so that our target count goes back to 0 and we are considered up-to-date.
[self.localStore releaseQuery:query];
2017-10-03 08:55:22 -07:00
[self writeMutation:FSTTestSetMutation(@"foo/bah", @{@"foo" : @"bah"})];
[self writeMutation:FSTTestDeleteMutation(@"foo/baz")];
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations));
FSTAssertContains(FSTTestDoc("foo/bah", 0, @{@"foo" : @"bah"}, FSTDocumentStateLocalMutations));
FSTAssertContains(FSTTestDeletedDoc("foo/baz", 0, NO));
2017-10-03 08:55:22 -07:00
[self acknowledgeMutationWithVersion:3];
FSTAssertNotContains(@"foo/bar");
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDoc("foo/bah", 0, @{@"foo" : @"bah"}, FSTDocumentStateLocalMutations));
FSTAssertContains(FSTTestDeletedDoc("foo/baz", 0, NO));
2017-10-03 08:55:22 -07:00
[self acknowledgeMutationWithVersion:4];
FSTAssertNotContains(@"foo/bar");
FSTAssertNotContains(@"foo/bah");
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDeletedDoc("foo/baz", 0, NO));
2017-10-03 08:55:22 -07:00
[self acknowledgeMutationWithVersion:5];
FSTAssertNotContains(@"foo/bar");
FSTAssertNotContains(@"foo/bah");
FSTAssertNotContains(@"foo/baz");
}
- (void)testCollectsGarbageAfterRejectedMutation {
if ([self isTestBaseClass]) return;
2018-07-27 13:58:11 -07:00
if (![self gcIsEager]) return;
2017-10-03 08:55:22 -07:00
2018-04-16 12:18:35 -07:00
FSTQuery *query = FSTTestQuery("foo");
2018-08-15 15:56:45 -07:00
TargetId targetID = [self allocateQuery:query];
2018-04-16 12:18:35 -07:00
2018-11-01 09:44:30 -07:00
[self applyRemoteEvent:FSTTestUpdateRemoteEvent(
FSTTestDoc("foo/bar", 0, @{@"foo" : @"old"}, FSTDocumentStateSynced),
2019-01-23 17:26:49 -05:00
{targetID}, {})];
[self writeMutation:FSTTestPatchMutation("foo/bar", @{@"foo" : @"bar"}, {})];
2018-04-16 12:18:35 -07:00
// Release the query so that our target count goes back to 0 and we are considered up-to-date.
[self.localStore releaseQuery:query];
2017-10-03 08:55:22 -07:00
[self writeMutation:FSTTestSetMutation(@"foo/bah", @{@"foo" : @"bah"})];
[self writeMutation:FSTTestDeleteMutation(@"foo/baz")];
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations));
FSTAssertContains(FSTTestDoc("foo/bah", 0, @{@"foo" : @"bah"}, FSTDocumentStateLocalMutations));
FSTAssertContains(FSTTestDeletedDoc("foo/baz", 0, NO));
2017-10-03 08:55:22 -07:00
[self rejectMutation]; // patch mutation
FSTAssertNotContains(@"foo/bar");
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDoc("foo/bah", 0, @{@"foo" : @"bah"}, FSTDocumentStateLocalMutations));
FSTAssertContains(FSTTestDeletedDoc("foo/baz", 0, NO));
2017-10-03 08:55:22 -07:00
[self rejectMutation]; // set mutation
FSTAssertNotContains(@"foo/bar");
FSTAssertNotContains(@"foo/bah");
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDeletedDoc("foo/baz", 0, NO));
2017-10-03 08:55:22 -07:00
[self rejectMutation]; // delete mutation
FSTAssertNotContains(@"foo/bar");
FSTAssertNotContains(@"foo/bah");
FSTAssertNotContains(@"foo/baz");
}
- (void)testPinsDocumentsInTheLocalView {
if ([self isTestBaseClass]) return;
2018-07-27 13:58:11 -07:00
if (![self gcIsEager]) return;
2017-10-03 08:55:22 -07:00
FSTQuery *query = FSTTestQuery("foo");
2018-08-15 15:56:45 -07:00
TargetId targetID = [self allocateQuery:query];
2017-10-03 08:55:22 -07:00
2018-11-01 09:44:30 -07:00
[self applyRemoteEvent:FSTTestAddedRemoteEvent(
FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, FSTDocumentStateSynced),
2019-01-23 17:26:49 -05:00
{targetID})];
2017-10-03 08:55:22 -07:00
[self writeMutation:FSTTestSetMutation(@"foo/baz", @{@"foo" : @"baz"})];
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, FSTDocumentStateSynced));
FSTAssertContains(FSTTestDoc("foo/baz", 0, @{@"foo" : @"baz"}, FSTDocumentStateLocalMutations));
2017-10-03 08:55:22 -07:00
[self notifyLocalViewChanges:FSTTestViewChanges(targetID, @[ @"foo/bar", @"foo/baz" ], @[])];
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, FSTDocumentStateSynced));
[self applyRemoteEvent:FSTTestUpdateRemoteEvent(
FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, FSTDocumentStateSynced),
2019-01-23 17:26:49 -05:00
{}, {targetID})];
2018-11-01 09:44:30 -07:00
[self applyRemoteEvent:FSTTestUpdateRemoteEvent(
FSTTestDoc("foo/baz", 2, @{@"foo" : @"baz"}, FSTDocumentStateSynced),
2019-01-23 17:26:49 -05:00
{targetID}, {})];
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDoc("foo/baz", 2, @{@"foo" : @"baz"}, FSTDocumentStateLocalMutations));
2017-10-03 08:55:22 -07:00
[self acknowledgeMutationWithVersion:2];
2018-11-01 09:44:30 -07:00
FSTAssertContains(FSTTestDoc("foo/baz", 2, @{@"foo" : @"baz"}, FSTDocumentStateSynced));
FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, FSTDocumentStateSynced));
FSTAssertContains(FSTTestDoc("foo/baz", 2, @{@"foo" : @"baz"}, FSTDocumentStateSynced));
2017-10-03 08:55:22 -07:00
[self notifyLocalViewChanges:FSTTestViewChanges(targetID, @[], @[ @"foo/bar", @"foo/baz" ])];
2018-04-16 12:18:35 -07:00
[self.localStore releaseQuery:query];
2017-10-03 08:55:22 -07:00
FSTAssertNotContains(@"foo/bar");
FSTAssertNotContains(@"foo/baz");
}
- (void)testThrowsAwayDocumentsWithUnknownTargetIDsImmediately {
if ([self isTestBaseClass]) return;
2018-07-27 13:58:11 -07:00
if (![self gcIsEager]) return;
2017-10-03 08:55:22 -07:00
2018-08-15 15:56:45 -07:00
TargetId targetID = 321;
2018-11-01 09:44:30 -07:00
[self applyRemoteEvent:FSTTestUpdateRemoteEventWithLimboTargets(
2019-01-23 17:26:49 -05:00
FSTTestDoc("foo/bar", 1, @{}, FSTDocumentStateSynced), {}, {},
{targetID})];
2017-10-03 08:55:22 -07:00
FSTAssertNotContains(@"foo/bar");
}
- (void)testCanExecuteDocumentQueries {
if ([self isTestBaseClass]) return;
2019-02-07 22:03:17 -05:00
[self.localStore locallyWriteMutations:{
2017-10-03 08:55:22 -07:00
FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"}),
2019-02-07 22:03:17 -05:00
FSTTestSetMutation(@"foo/baz", @{@"foo" : @"baz"}),
FSTTestSetMutation(@"foo/bar/Foo/Bar", @{@"Foo" : @"Bar"})
}];
FSTQuery *query = FSTTestQuery("foo/bar");
DocumentMap docs = [self.localStore executeQuery:query];
XCTAssertEqualObjects(docMapToArray(docs), @[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"},
FSTDocumentStateLocalMutations) ]);
2017-10-03 08:55:22 -07:00
}
- (void)testCanExecuteCollectionQueries {
if ([self isTestBaseClass]) return;
2019-02-07 22:03:17 -05:00
[self.localStore locallyWriteMutations:{
2017-10-03 08:55:22 -07:00
FSTTestSetMutation(@"fo/bar", @{@"fo" : @"bar"}),
2019-02-07 22:03:17 -05:00
FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"}),
FSTTestSetMutation(@"foo/baz", @{@"foo" : @"baz"}),
FSTTestSetMutation(@"foo/bar/Foo/Bar", @{@"Foo" : @"Bar"}),
FSTTestSetMutation(@"fooo/blah", @{@"fooo" : @"blah"})
}];
FSTQuery *query = FSTTestQuery("foo");
DocumentMap docs = [self.localStore executeQuery:query];
2018-11-01 09:44:30 -07:00
XCTAssertEqualObjects(
docMapToArray(docs), (@[
2018-11-01 09:44:30 -07:00
FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, FSTDocumentStateLocalMutations),
FSTTestDoc("foo/baz", 0, @{@"foo" : @"baz"}, FSTDocumentStateLocalMutations)
]));
2017-10-03 08:55:22 -07:00
}
- (void)testCanExecuteMixedCollectionQueries {
if ([self isTestBaseClass]) return;
FSTQuery *query = FSTTestQuery("foo");
2017-10-03 08:55:22 -07:00
[self allocateQuery:query];
FSTAssertTargetID(2);
2018-11-01 09:44:30 -07:00
[self applyRemoteEvent:FSTTestUpdateRemoteEvent(
2019-01-23 17:26:49 -05:00
FSTTestDoc("foo/baz", 10, @{@"a" : @"b"}, FSTDocumentStateSynced), {2},
{})];
2018-11-01 09:44:30 -07:00
[self applyRemoteEvent:FSTTestUpdateRemoteEvent(
2019-01-23 17:26:49 -05:00
FSTTestDoc("foo/bar", 20, @{@"a" : @"b"}, FSTDocumentStateSynced), {2},
{})];
2017-10-03 08:55:22 -07:00
2019-02-07 22:03:17 -05:00
[self.localStore locallyWriteMutations:{ FSTTestSetMutation(@"foo/bonk", @{@"a" : @"b"}) }];
2017-10-03 08:55:22 -07:00
DocumentMap docs = [self.localStore executeQuery:query];
XCTAssertEqualObjects(docMapToArray(docs), (@[
2018-11-01 09:44:30 -07:00
FSTTestDoc("foo/bar", 20, @{@"a" : @"b"}, FSTDocumentStateSynced),
FSTTestDoc("foo/baz", 10, @{@"a" : @"b"}, FSTDocumentStateSynced),
FSTTestDoc("foo/bonk", 0, @{@"a" : @"b"}, FSTDocumentStateLocalMutations)
2017-10-03 08:55:22 -07:00
]));
}
- (void)testPersistsResumeTokens {
if ([self isTestBaseClass]) return;
// This test only works in the absence of the FSTEagerGarbageCollector.
2018-07-27 13:58:11 -07:00
if ([self gcIsEager]) return;
2017-10-03 08:55:22 -07:00
FSTQuery *query = FSTTestQuery("foo/bar");
2017-10-03 08:55:22 -07:00
FSTQueryData *queryData = [self.localStore allocateQuery:query];
ListenSequenceNumber initialSequenceNumber = queryData.sequenceNumber;
2019-01-23 17:26:49 -05:00
TargetId targetID = queryData.targetID;
2017-10-03 08:55:22 -07:00
NSData *resumeToken = FSTTestResumeTokenFromSnapshotVersion(1000);
2019-01-23 17:26:49 -05:00
WatchTargetChange watchChange{WatchTargetChangeState::Current, {targetID}, resumeToken};
auto metadataProvider = TestTargetMetadataProvider::CreateSingleResultProvider(
testutil::Key("foo/bar"), std::vector<TargetId>{targetID});
WatchChangeAggregator aggregator{&metadataProvider};
aggregator.HandleTargetChange(watchChange);
2019-01-29 18:55:25 -05:00
RemoteEvent remoteEvent = aggregator.CreateRemoteEvent(testutil::Version(1000));
2017-10-03 08:55:22 -07:00
[self applyRemoteEvent:remoteEvent];
// Stop listening so that the query should become inactive (but persistent)
[self.localStore releaseQuery:query];
// Should come back with the same resume token
FSTQueryData *queryData2 = [self.localStore allocateQuery:query];
XCTAssertEqualObjects(queryData2.resumeToken, resumeToken);
// The sequence number should have been bumped when we saved the new resume token.
ListenSequenceNumber newSequenceNumber = queryData2.sequenceNumber;
XCTAssertGreaterThan(newSequenceNumber, initialSequenceNumber);
2017-10-03 08:55:22 -07:00
}
- (void)testRemoteDocumentKeysForTarget {
if ([self isTestBaseClass]) return;
FSTQuery *query = FSTTestQuery("foo");
2017-10-03 08:55:22 -07:00
[self allocateQuery:query];
FSTAssertTargetID(2);
2019-01-23 17:26:49 -05:00
[self
applyRemoteEvent:FSTTestAddedRemoteEvent(
FSTTestDoc("foo/baz", 10, @{@"a" : @"b"}, FSTDocumentStateSynced), {2})];
[self
applyRemoteEvent:FSTTestAddedRemoteEvent(
FSTTestDoc("foo/bar", 20, @{@"a" : @"b"}, FSTDocumentStateSynced), {2})];
2017-10-03 08:55:22 -07:00
2019-02-07 22:03:17 -05:00
[self.localStore locallyWriteMutations:{ FSTTestSetMutation(@"foo/bonk", @{@"a" : @"b"}) }];
2017-10-03 08:55:22 -07:00
DocumentKeySet keys = [self.localStore remoteDocumentKeysForTarget:2];
DocumentKeySet expected{testutil::Key("foo/bar"), testutil::Key("foo/baz")};
XCTAssertEqual(keys, expected);
2017-10-03 08:55:22 -07:00
keys = [self.localStore remoteDocumentKeysForTarget:2];
XCTAssertEqual(keys, (DocumentKeySet{testutil::Key("foo/bar"), testutil::Key("foo/baz")}));
2017-10-03 08:55:22 -07:00
}
2019-03-06 14:51:30 -08:00
// TODO(mrschmidt): The FieldValue.increment() field transform tests below would probably be
// better implemented as spec tests but currently they don't support transforms.
- (void)testHandlesSetMutationThenTransformMutationThenTransformMutation {
if ([self isTestBaseClass]) return;
[self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"sum" : @0})];
FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"sum" : @0}, FSTDocumentStateLocalMutations));
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"sum" : @0}, FSTDocumentStateLocalMutations) ]);
[self writeMutation:FSTTestTransformMutation(
@"foo/bar", @{@"sum" : [FIRFieldValue fieldValueForIntegerIncrement:1]})];
FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"sum" : @1}, FSTDocumentStateLocalMutations));
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"sum" : @1}, FSTDocumentStateLocalMutations) ]);
[self writeMutation:FSTTestTransformMutation(
@"foo/bar", @{@"sum" : [FIRFieldValue fieldValueForIntegerIncrement:2]})];
FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"sum" : @3}, FSTDocumentStateLocalMutations));
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"sum" : @3}, FSTDocumentStateLocalMutations) ]);
}
- (void)testHandlesSetMutationThenAckThenTransformMutationThenAckThenTransformMutation {
if ([self isTestBaseClass]) return;
// Since this test doesn't start a listen, Eager GC removes the documents from the cache as
// soon as the mutation is applied. This creates a lot of special casing in this unit test but
// does not expand its test coverage.
if ([self gcIsEager]) return;
[self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"sum" : @0})];
FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"sum" : @0}, FSTDocumentStateLocalMutations));
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"sum" : @0}, FSTDocumentStateLocalMutations) ]);
[self acknowledgeMutationWithVersion:1];
FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"sum" : @0}, FSTDocumentStateCommittedMutations));
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 1, @{@"sum" : @0}, FSTDocumentStateCommittedMutations) ]);
[self writeMutation:FSTTestTransformMutation(
@"foo/bar", @{@"sum" : [FIRFieldValue fieldValueForIntegerIncrement:1]})];
FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"sum" : @1}, FSTDocumentStateLocalMutations));
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"sum" : @1}, FSTDocumentStateLocalMutations) ]);
[self acknowledgeMutationWithVersion:2 transformResult:@1];
FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"sum" : @1}, FSTDocumentStateCommittedMutations));
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 2, @{@"sum" : @1}, FSTDocumentStateCommittedMutations) ]);
[self writeMutation:FSTTestTransformMutation(
@"foo/bar", @{@"sum" : [FIRFieldValue fieldValueForIntegerIncrement:2]})];
FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"sum" : @3}, FSTDocumentStateLocalMutations));
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 2, @{@"sum" : @3}, FSTDocumentStateLocalMutations) ]);
}
- (void)testHandlesSetMutationThenTransformMutationThenRemoteEventThenTransformMutation {
if ([self isTestBaseClass]) return;
FSTQuery *query = FSTTestQuery("foo");
[self allocateQuery:query];
FSTAssertTargetID(2);
[self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"sum" : @0})];
FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"sum" : @0}, FSTDocumentStateLocalMutations));
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"sum" : @0}, FSTDocumentStateLocalMutations) ]);
[self
applyRemoteEvent:FSTTestAddedRemoteEvent(
FSTTestDoc("foo/bar", 1, @{@"sum" : @0}, FSTDocumentStateSynced), {2})];
[self acknowledgeMutationWithVersion:1];
FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"sum" : @0}, FSTDocumentStateSynced));
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"sum" : @0}, FSTDocumentStateSynced) ]);
[self writeMutation:FSTTestTransformMutation(
@"foo/bar", @{@"sum" : [FIRFieldValue fieldValueForIntegerIncrement:1]})];
FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"sum" : @1}, FSTDocumentStateLocalMutations));
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"sum" : @1}, FSTDocumentStateLocalMutations) ]);
// The value in this remote event gets ignored since we still have a pending transform mutation.
[self applyRemoteEvent:FSTTestUpdateRemoteEvent(
FSTTestDoc("foo/bar", 2, @{@"sum" : @0}, FSTDocumentStateSynced), {2},
{})];
FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"sum" : @1}, FSTDocumentStateLocalMutations));
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 2, @{@"sum" : @1}, FSTDocumentStateLocalMutations) ]);
// Add another increment. Note that we still compute the increment based on the local value.
[self writeMutation:FSTTestTransformMutation(
@"foo/bar", @{@"sum" : [FIRFieldValue fieldValueForIntegerIncrement:2]})];
FSTAssertContains(FSTTestDoc("foo/bar", 2, @{@"sum" : @3}, FSTDocumentStateLocalMutations));
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 2, @{@"sum" : @3}, FSTDocumentStateLocalMutations) ]);
[self acknowledgeMutationWithVersion:3 transformResult:@1];
FSTAssertContains(FSTTestDoc("foo/bar", 3, @{@"sum" : @3}, FSTDocumentStateLocalMutations));
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 3, @{@"sum" : @3}, FSTDocumentStateLocalMutations) ]);
[self acknowledgeMutationWithVersion:4 transformResult:@1339];
FSTAssertContains(
FSTTestDoc("foo/bar", 4, @{@"sum" : @1339}, FSTDocumentStateCommittedMutations));
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 4, @{@"sum" : @1339}, FSTDocumentStateCommittedMutations) ]);
}
- (void)testHoldsBackOnlyNonIdempotentTransforms {
if ([self isTestBaseClass]) return;
FSTQuery *query = FSTTestQuery("foo");
[self allocateQuery:query];
FSTAssertTargetID(2);
[self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"sum" : @0, @"array_union" : @[]})];
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"sum" : @0, @"array_union" : @[]},
FSTDocumentStateLocalMutations) ]);
[self acknowledgeMutationWithVersion:1];
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"sum" : @0, @"array_union" : @[]},
FSTDocumentStateCommittedMutations) ]);
[self applyRemoteEvent:FSTTestAddedRemoteEvent(
FSTTestDoc("foo/bar", 1, @{@"sum" : @0, @"array_union" : @[]},
FSTDocumentStateSynced),
{2})];
FSTAssertChanged(
@[ FSTTestDoc("foo/bar", 1, @{@"sum" : @0, @"array_union" : @[]}, FSTDocumentStateSynced) ]);
[self writeMutations:{
FSTTestTransformMutation(@"foo/bar",
@{@"sum" : [FIRFieldValue fieldValueForIntegerIncrement:1]}),
FSTTestTransformMutation(
@"foo/bar",
@{@"array_union" : [FIRFieldValue fieldValueForArrayUnion:@[ @"foo" ]]})
}];
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"sum" : @1, @"array_union" : @[ @"foo" ]},
FSTDocumentStateLocalMutations) ]);
// The sum transform is not idempotent and the backend's updated value is ignored. The
// ArrayUnion transform is recomputed and includes the backend value.
[self
applyRemoteEvent:FSTTestUpdateRemoteEvent(
FSTTestDoc("foo/bar", 1, @{@"sum" : @1337, @"array_union" : @[ @"bar" ]},
FSTDocumentStateSynced),
{2}, {})];
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"sum" : @1, @"array_union" : @[ @"bar", @"foo" ]},
FSTDocumentStateLocalMutations) ]);
}
- (void)testHandlesMergeMutationWithTransformThenRemoteEvent {
if ([self isTestBaseClass]) return;
FSTQuery *query = FSTTestQuery("foo");
[self allocateQuery:query];
FSTAssertTargetID(2);
[self writeMutations:{
FSTTestPatchMutation("foo/bar", @{}, {firebase::firestore::testutil::Field("sum")}),
FSTTestTransformMutation(@"foo/bar",
@{@"sum" : [FIRFieldValue fieldValueForIntegerIncrement:1]})
}];
FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"sum" : @1}, FSTDocumentStateLocalMutations));
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"sum" : @1}, FSTDocumentStateLocalMutations) ]);
[self applyRemoteEvent:FSTTestAddedRemoteEvent(
FSTTestDoc("foo/bar", 1, @{@"sum" : @1337}, FSTDocumentStateSynced),
{2})];
FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"sum" : @1}, FSTDocumentStateLocalMutations));
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"sum" : @1}, FSTDocumentStateLocalMutations) ]);
}
- (void)testHandlesPatchMutationWithTransformThenRemoteEvent {
if ([self isTestBaseClass]) return;
FSTQuery *query = FSTTestQuery("foo");
[self allocateQuery:query];
FSTAssertTargetID(2);
[self writeMutations:{
FSTTestPatchMutation("foo/bar", @{}, {}),
FSTTestTransformMutation(@"foo/bar",
@{@"sum" : [FIRFieldValue fieldValueForIntegerIncrement:1]})
}];
FSTAssertNotContains(@"foo/bar");
FSTAssertChanged(@[ FSTTestDeletedDoc("foo/bar", 0, NO) ]);
// Note: This test reflects the current behavior, but it may be preferable to replay the
// mutation once we receive the first value from the remote event.
[self applyRemoteEvent:FSTTestAddedRemoteEvent(
FSTTestDoc("foo/bar", 1, @{@"sum" : @1337}, FSTDocumentStateSynced),
{2})];
FSTAssertContains(FSTTestDoc("foo/bar", 1, @{@"sum" : @1}, FSTDocumentStateLocalMutations));
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 1, @{@"sum" : @1}, FSTDocumentStateLocalMutations) ]);
}
2017-10-03 08:55:22 -07:00
@end
NS_ASSUME_NONNULL_END