-
Notifications
You must be signed in to change notification settings - Fork 150
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
feat: Add totalDocuments and totalBytes to bundle metadata. #1085
Conversation
Codecov Report
@@ Coverage Diff @@
## node10 #1085 +/- ##
=======================================
Coverage 98.62% 98.63%
=======================================
Files 28 28
Lines 17944 18009 +65
Branches 1394 1399 +5
=======================================
+ Hits 17698 17763 +65
Misses 243 243
Partials 3 3
Continue to review full report at Codecov.
|
bundleBuffer = Buffer.concat([ | ||
this.elementToLengthPrefixedBuffer({metadata}), | ||
bundleBuffer, | ||
]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I understand how this will work. I assume this was added to allow the progress handler to display their status. For that to work, would this not need to be the first message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note the order of the arguments to Buffer.concat
is different here. Also added a comment.
dev/src/bundle.ts
Outdated
totalDocuments: this.documents.size, | ||
totalBytes: bundleBuffer.length, | ||
}; | ||
// Prepends the metadata element to the bundleBuffer, note `bundleBuffer` is the second argument to `Buffer.concat`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/, note/:/
// Prepends the metadata element to the bundleBuffer: `bundleBuffer` is the second argument to `Buffer.concat`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
dev/test/bundle.ts
Outdated
@@ -80,11 +80,14 @@ describe('Bundle Buidler', () => { | |||
expect(elements.length).to.equal(3); | |||
|
|||
const meta = (elements[0] as IBundleElement).metadata; | |||
expect(meta!.totalBytes).greaterThan(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the size not fixed here in the unit tests? Or will that make the tests too fragile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I started with checking for exact size, but it became too fragile.
@@ -128,11 +131,14 @@ describe('Bundle Buidler', () => { | |||
expect(elements.length).to.equal(4); | |||
|
|||
const meta = (elements[0] as IBundleElement).metadata; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind adding a helper for the metadata comparison?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
dev/test/bundle.ts
Outdated
meta: IBundleMetadata, | ||
expected: IBundleMetadata | ||
): void { | ||
expect(meta!.totalBytes).greaterThan(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
dev/test/bundle.ts
Outdated
|
||
export function verifyMetadata( | ||
meta: IBundleMetadata, | ||
expected: IBundleMetadata |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping you would pass in the expected state one at a time:
export function verifyMetadata(
meta: IBundleMetadata,
id: string,
createTime: ReadTime,
version: number,
totalDocuments: 0
)
From that, you can simplify further. Extract a constant for the bundle ID, and use it everywhere. The version is also always a constant. So in the end you have:
export function verifyMetadata(
meta: IBundleMetadata,
createTime: ReadTime,
totalDocuments: 0
)
You can then also compare each field directly:
expect(meta.totalBytes).greaterThan(0);
expect(meta.id).to.equal(BUNDLE_ID);
expect(meta.version).to.equal(1);
expect(meta.createTime).to.deep.equal(readTime.toProto());
expect(meta.totalDocuments).to.equal(totalDocuments);
This removes the need to delete the field and ruins nasty surprises in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice! Thanks!
If you want to spend more time on this, I'd suggest prefixing the "totalDocuments" argument with /* totalDocuments= */
for better readability. But even without this, this is good to go.
* fix!: mark v1beta1 client as deprecated (#937) * feat!: use QueryDocumentSnapshot in FirestoreDataConverter (#965) * deps: update to gts 2.x (#1013) * chore!: update settings for Node 10 (#1019) * deps: drop through2 (#1014) * feat: support BigInt (#1016) * fix: make update.sh work on Linux (#1043) * fix: only use BigInt in BigInt system test (#1044) * fix: make pbjs compile admin proto again (#1045) * Add BulkWriter (#1055) * docs: Add documentation for FirestoreDataConverter (#1059) * chore: enforce return types (#1065) * fix: add generic to Firestore.getAll() (#1066) * chore: remove internal WriteOp (#1067) * chore: add linter checks for it|describe.only (#1068) * fix: handle terminate in BulkWriter (#1070) * chore: run template copying last in synthtool (#1071) * feat: Firestore Bundles implementation (#1078) * feat: add support for set() with SetOptions when using FirestoreDataConverter (#1087) * feat: Add totalDocuments and totalBytes to bundle metadata. (#1085) * feat: Add totalDocuments and totalBytes to bundle metadata. * fix: Better comment * fix: Better testing. * fix: Improve metadata testing. * fix: incomplete expect in rate-limiter test (#1092) * Remove BatchWrite proto, fix conformance tests * chore: use public API types internally (#1100) * feat: add Partition and BatchWrite protos (#1110) * fix: remove GCF transaction fallback (#1112) * fix: add BulkWriter integration tests, java backport changes, delete fix (#1117) * chore: merge master (#1218) * chore: add eslint check for console.log statements (#1229) * fix: another attempt at fixing the flaky BulkWriter test (#1228) * Fix comment * Renames * Test fix * Fix unit tests Co-authored-by: Brian Chen <[email protected]> Co-authored-by: wu-hui <[email protected]>
Source-Link: googleapis/synthtool@4dfd20a Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-nodejs:latest@sha256:2d850512335d7adca3a4b08e02f8e63192978aea88c042dacb3e382aa996ae7c
No description provided.