Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unchanged names to existence filter and watchFilters spec test runner #10862

Merged
merged 18 commits into from
Mar 18, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions Firestore/Example/Firestore.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

24 changes: 20 additions & 4 deletions Firestore/Example/Tests/SpecTests/FSTSpecTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include "Firestore/core/src/model/types.h"
#include "Firestore/core/src/nanopb/message.h"
#include "Firestore/core/src/nanopb/nanopb_util.h"
#include "Firestore/core/src/remote/bloom_filter.h"
#include "Firestore/core/src/remote/existence_filter.h"
#include "Firestore/core/src/remote/serializer.h"
#include "Firestore/core/src/remote/watch_change.h"
Expand All @@ -70,7 +71,9 @@
#include "Firestore/core/src/util/string_apple.h"
#include "Firestore/core/src/util/to_string.h"
#include "Firestore/core/test/unit/testutil/testutil.h"

#include "absl/memory/memory.h"
#include "absl/strings/escaping.h"
#include "absl/types/optional.h"

namespace objc = firebase::firestore::objc;
Expand Down Expand Up @@ -98,6 +101,7 @@
using firebase::firestore::nanopb::ByteString;
using firebase::firestore::nanopb::MakeByteString;
using firebase::firestore::nanopb::Message;
using firebase::firestore::remote::BloomFilter;
using firebase::firestore::remote::DocumentWatchChange;
using firebase::firestore::remote::ExistenceFilter;
using firebase::firestore::remote::ExistenceFilterWatchChange;
Expand All @@ -115,6 +119,7 @@
using firebase::firestore::util::MakeStringPtr;
using firebase::firestore::util::Path;
using firebase::firestore::util::Status;
using firebase::firestore::util::StatusOr;
using firebase::firestore::util::TimerId;
using firebase::firestore::util::ToString;
using firebase::firestore::util::WrapCompare;
Expand Down Expand Up @@ -325,6 +330,14 @@ - (SnapshotVersion)parseVersion:(NSNumber *_Nullable)version {
return Version(version.longLongValue);
}

- (absl::optional<BloomFilter>)parseBloomFilter:(NSDictionary *_Nullable)bloomFilterProto {
dconeybe marked this conversation as resolved.
Show resolved Hide resolved
// TODO(Mila): None of the ported spec tests actually has the bloom filter json string, so hard
// code a null value for now. Actual parsing code will be written in the next PR, where we can
// validate the parsing result.
return absl::nullopt;
;
dconeybe marked this conversation as resolved.
Show resolved Hide resolved
}

- (DocumentViewChange)parseChange:(NSDictionary *)jsonDoc ofType:(DocumentViewChange::Type)type {
NSNumber *version = jsonDoc[@"version"];
NSDictionary *options = jsonDoc[@"options"];
Expand Down Expand Up @@ -463,13 +476,16 @@ - (void)doWatchEntity:(NSDictionary *)watchEntity {
}
}

- (void)doWatchFilter:(NSArray *)watchFilter {
NSArray<NSNumber *> *targets = watchFilter[0];
- (void)doWatchFilter:(NSDictionary *)watchFilter {
NSArray<NSNumber *> *targets = watchFilter[@"targetIds"];
HARD_ASSERT(targets.count == 1, "ExistenceFilters currently support exactly one target only.");

int keyCount = watchFilter.count == 0 ? 0 : (int)watchFilter.count - 1;
NSArray<NSNumber *> *keys = watchFilter[@"keys"];
int keyCount = keys ? (int)keys.count : 0;

absl::optional<BloomFilter> bloomFilter = [self parseBloomFilter:watchFilter[@"bloomFilter"]];

ExistenceFilter filter{keyCount};
ExistenceFilter filter{keyCount, bloomFilter};
dconeybe marked this conversation as resolved.
Show resolved Hide resolved
ExistenceFilterWatchChange change{filter, targets[0].intValue};
dconeybe marked this conversation as resolved.
Show resolved Hide resolved
[self.driver receiveWatchChange:change snapshotVersion:SnapshotVersion::None()];
}
Expand Down
114 changes: 67 additions & 47 deletions Firestore/Example/Tests/SpecTests/json/existence_filter_spec_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@
]
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1"
],
"collection/1"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down Expand Up @@ -341,13 +343,15 @@
]
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1",
"collection/2"
],
"collection/1",
"collection/2"
]
"targetIds": [
2
]
}
},
{
"watchEntity": {
Expand Down Expand Up @@ -694,11 +698,13 @@
}
},
{
"watchFilter": [
[
"watchFilter": {
"keys": [
],
"targetIds": [
2
]
]
}
},
{
"watchRemove": {
Expand Down Expand Up @@ -871,12 +877,14 @@
]
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1"
],
"collection/1"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down Expand Up @@ -1156,12 +1164,14 @@
]
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1"
],
"collection/1"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down Expand Up @@ -1265,12 +1275,14 @@
}
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1"
],
"collection/1"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down Expand Up @@ -1436,12 +1448,14 @@
]
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1"
],
"collection/1"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down Expand Up @@ -1783,12 +1797,14 @@
]
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1"
],
"collection/1"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down Expand Up @@ -2078,11 +2094,13 @@
]
},
{
"watchFilter": [
[
"watchFilter": {
"keys": [
],
"targetIds": [
2
]
]
}
},
{
"watchSnapshot": {
Expand Down Expand Up @@ -2193,12 +2211,14 @@
]
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/1"
],
"collection/1"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down
24 changes: 14 additions & 10 deletions Firestore/Example/Tests/SpecTests/json/limbo_spec_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -3386,11 +3386,13 @@
]
},
{
"watchFilter": [
[
"watchFilter": {
"keys": [
],
"targetIds": [
1
]
]
}
},
{
"watchCurrent": [
Expand Down Expand Up @@ -8036,14 +8038,16 @@
}
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/b1",
"collection/b2",
"collection/b3"
],
"collection/b1",
"collection/b2",
"collection/b3"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down
12 changes: 7 additions & 5 deletions Firestore/Example/Tests/SpecTests/json/limit_spec_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -5455,12 +5455,14 @@
}
},
{
"watchFilter": [
[
2
"watchFilter": {
"keys": [
"collection/b"
],
"collection/b"
]
"targetIds": [
2
]
}
},
{
"watchSnapshot": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const pb_field_t google_firestore_v1_BitSequence_fields[3] = {
};

const pb_field_t google_firestore_v1_BloomFilter_fields[3] = {
PB_FIELD( 1, MESSAGE , SINGULAR, STATIC , FIRST, google_firestore_v1_BloomFilter, bits, bits, &google_firestore_v1_BitSequence_fields),
PB_FIELD( 1, MESSAGE , OPTIONAL, STATIC , FIRST, google_firestore_v1_BloomFilter, bits, bits, &google_firestore_v1_BitSequence_fields),
PB_FIELD( 2, INT32 , SINGULAR, STATIC , OTHER, google_firestore_v1_BloomFilter, hash_count, bits, 0),
PB_LAST_FIELD
};
Expand Down Expand Up @@ -96,7 +96,9 @@ std::string google_firestore_v1_BloomFilter::ToString(int indent) const {
std::string tostring_header = PrintHeader(indent, "BloomFilter", this);
std::string tostring_result;

tostring_result += PrintMessageField("bits ", bits, indent + 1, false);
if (has_bits) {
tostring_result += PrintMessageField("bits ", bits, indent + 1, true);
}
tostring_result += PrintPrimitiveField("hash_count: ",
hash_count, indent + 1, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ typedef struct _google_firestore_v1_BitSequence {
} google_firestore_v1_BitSequence;

typedef struct _google_firestore_v1_BloomFilter {
bool has_bits;
google_firestore_v1_BitSequence bits;
int32_t hash_count;

Expand All @@ -53,9 +54,9 @@ typedef struct _google_firestore_v1_BloomFilter {

/* Initializer values for message structs */
#define google_firestore_v1_BitSequence_init_default {NULL, 0}
#define google_firestore_v1_BloomFilter_init_default {google_firestore_v1_BitSequence_init_default, 0}
#define google_firestore_v1_BloomFilter_init_default {false, google_firestore_v1_BitSequence_init_default, 0}
#define google_firestore_v1_BitSequence_init_zero {NULL, 0}
#define google_firestore_v1_BloomFilter_init_zero {google_firestore_v1_BitSequence_init_zero, 0}
#define google_firestore_v1_BloomFilter_init_zero {false, google_firestore_v1_BitSequence_init_zero, 0}

/* Field tags (for use in manual encoding/decoding) */
#define google_firestore_v1_BitSequence_bitmap_tag 1
Expand Down
8 changes: 5 additions & 3 deletions Firestore/Protos/nanopb/google/firestore/v1/write.nanopb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const pb_field_t google_firestore_v1_DocumentRemove_fields[4] = {
const pb_field_t google_firestore_v1_ExistenceFilter_fields[4] = {
PB_FIELD( 1, INT32 , SINGULAR, STATIC , FIRST, google_firestore_v1_ExistenceFilter, target_id, target_id, 0),
PB_FIELD( 2, INT32 , SINGULAR, STATIC , OTHER, google_firestore_v1_ExistenceFilter, count, target_id, 0),
PB_FIELD( 3, MESSAGE , SINGULAR, STATIC , OTHER, google_firestore_v1_ExistenceFilter, unchanged_names, count, &google_firestore_v1_BloomFilter_fields),
PB_FIELD( 3, MESSAGE , OPTIONAL, STATIC , OTHER, google_firestore_v1_ExistenceFilter, unchanged_names, count, &google_firestore_v1_BloomFilter_fields),
PB_LAST_FIELD
};

Expand Down Expand Up @@ -317,8 +317,10 @@ std::string google_firestore_v1_ExistenceFilter::ToString(int indent) const {
target_id, indent + 1, false);
tostring_result += PrintPrimitiveField("count: ",
count, indent + 1, false);
tostring_result += PrintMessageField("unchanged_names ",
unchanged_names, indent + 1, false);
if (has_unchanged_names) {
tostring_result += PrintMessageField("unchanged_names ",
unchanged_names, indent + 1, true);
}

std::string tostring_tail = PrintTail(indent);
return tostring_header + tostring_result + tostring_tail;
Expand Down
Loading