From 3f22a322151ed9f89586af94e52a6847654a3681 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Mon, 16 Dec 2024 11:03:10 -0500 Subject: [PATCH 1/9] fix(NODE-6608): calculateObjectSize returns the wrong value for bigint --- src/parser/calculate_size.ts | 3 +++ test/node/parser/calculate_size.test.ts | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/parser/calculate_size.ts b/src/parser/calculate_size.ts index 923beeb0b..da62ae6cd 100644 --- a/src/parser/calculate_size.ts +++ b/src/parser/calculate_size.ts @@ -205,6 +205,9 @@ function calculateElement( 1 ); } + return 0; + case 'bigint': + return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (8 + 1); } return 0; diff --git a/test/node/parser/calculate_size.test.ts b/test/node/parser/calculate_size.test.ts index 3ebccd160..e421c28f2 100644 --- a/test/node/parser/calculate_size.test.ts +++ b/test/node/parser/calculate_size.test.ts @@ -24,4 +24,10 @@ describe('calculateSize()', () => { }) ).to.throw(BSONVersionError, /Unsupported BSON version/i); }); + + it('returns the correct size for a bigint value', function () { + const doc = { a: BigInt(1) }; + expect(BSON.calculateObjectSize(doc)).to.equal(16); + expect(BSON.calculateObjectSize(doc)).to.equal(BSON.serialize(doc).byteLength); + }); }); From 4443177b9ce6cbf22ec51fb3eea5ca6ec748c073 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Mon, 16 Dec 2024 11:16:24 -0500 Subject: [PATCH 2/9] chore: add symbol coverage and error case --- src/parser/calculate_size.ts | 6 +++++- test/node/parser/calculate_size.test.ts | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/parser/calculate_size.ts b/src/parser/calculate_size.ts index da62ae6cd..557d15a8b 100644 --- a/src/parser/calculate_size.ts +++ b/src/parser/calculate_size.ts @@ -1,6 +1,6 @@ import { Binary } from '../binary'; import type { Document } from '../bson'; -import { BSONVersionError } from '../error'; +import { BSONError, BSONVersionError } from '../error'; import * as constants from '../constants'; import { ByteUtils } from '../utils/byte_utils'; import { isAnyArrayBuffer, isDate, isRegExp } from './utils'; @@ -208,6 +208,10 @@ function calculateElement( return 0; case 'bigint': return (name != null ? ByteUtils.utf8ByteLength(name) + 1 : 0) + (8 + 1); + case 'symbol': + return 0; + default: + throw new BSONError(`Unrecognized JS type: ${typeof value}`); } return 0; diff --git a/test/node/parser/calculate_size.test.ts b/test/node/parser/calculate_size.test.ts index e421c28f2..d7d3387c3 100644 --- a/test/node/parser/calculate_size.test.ts +++ b/test/node/parser/calculate_size.test.ts @@ -25,9 +25,15 @@ describe('calculateSize()', () => { ).to.throw(BSONVersionError, /Unsupported BSON version/i); }); - it('returns the correct size for a bigint value', function () { + it('returns 8 bytes (+7 meta bytes) size for a bigint value', function () { const doc = { a: BigInt(1) }; expect(BSON.calculateObjectSize(doc)).to.equal(16); expect(BSON.calculateObjectSize(doc)).to.equal(BSON.serialize(doc).byteLength); }); + + it('returns 0 bytes (+5 meta bytes) for a symbol value', function () { + const doc = { a: Symbol() }; + expect(BSON.calculateObjectSize(doc)).to.equal(5); + expect(BSON.calculateObjectSize(doc)).to.equal(BSON.serialize(doc).byteLength); + }); }); From c2bfe36256d0d278613cc2a35105827113c2e14e Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Mon, 16 Dec 2024 11:22:54 -0500 Subject: [PATCH 3/9] test: skip bigint test on proper platform --- test/node/parser/calculate_size.test.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/test/node/parser/calculate_size.test.ts b/test/node/parser/calculate_size.test.ts index d7d3387c3..1c119da4d 100644 --- a/test/node/parser/calculate_size.test.ts +++ b/test/node/parser/calculate_size.test.ts @@ -25,10 +25,18 @@ describe('calculateSize()', () => { ).to.throw(BSONVersionError, /Unsupported BSON version/i); }); - it('returns 8 bytes (+7 meta bytes) size for a bigint value', function () { - const doc = { a: BigInt(1) }; - expect(BSON.calculateObjectSize(doc)).to.equal(16); - expect(BSON.calculateObjectSize(doc)).to.equal(BSON.serialize(doc).byteLength); + describe('bigint', function () { + beforeEach(function () { + if (BSON.__noBigInt__) { + this.currentTest?.skip(); + } + }); + + it('returns 8 bytes (+7 meta bytes) size for a bigint value', function () { + const doc = { a: BigInt(1) }; + expect(BSON.calculateObjectSize(doc)).to.equal(16); + expect(BSON.calculateObjectSize(doc)).to.equal(BSON.serialize(doc).byteLength); + }); }); it('returns 0 bytes (+5 meta bytes) for a symbol value', function () { From 7a2a9b78d18093b06f12a066781b37cb2ff75f0d Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Mon, 16 Dec 2024 11:23:48 -0500 Subject: [PATCH 4/9] test: name fix --- test/node/parser/calculate_size.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/node/parser/calculate_size.test.ts b/test/node/parser/calculate_size.test.ts index 1c119da4d..2cf873726 100644 --- a/test/node/parser/calculate_size.test.ts +++ b/test/node/parser/calculate_size.test.ts @@ -32,7 +32,7 @@ describe('calculateSize()', () => { } }); - it('returns 8 bytes (+7 meta bytes) size for a bigint value', function () { + it('returns 8 bytes (+8 meta bytes) size for a bigint value', function () { const doc = { a: BigInt(1) }; expect(BSON.calculateObjectSize(doc)).to.equal(16); expect(BSON.calculateObjectSize(doc)).to.equal(BSON.serialize(doc).byteLength); From 43e8725e0fd49d9f0bdd3eea1cf8f19555fdff1c Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Mon, 16 Dec 2024 15:07:06 -0500 Subject: [PATCH 5/9] test: fix titles --- test/node/parser/calculate_size.test.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/node/parser/calculate_size.test.ts b/test/node/parser/calculate_size.test.ts index 2cf873726..62c7852b6 100644 --- a/test/node/parser/calculate_size.test.ts +++ b/test/node/parser/calculate_size.test.ts @@ -25,23 +25,25 @@ describe('calculateSize()', () => { ).to.throw(BSONVersionError, /Unsupported BSON version/i); }); - describe('bigint', function () { + describe('when given a bigint value with a single character key', function () { beforeEach(function () { if (BSON.__noBigInt__) { this.currentTest?.skip(); } }); - it('returns 8 bytes (+8 meta bytes) size for a bigint value', function () { + it('returns 8 bytes (+4 bytes for document size + 1 type byte + 1 byte for "a" + 2 null terminators)', function () { const doc = { a: BigInt(1) }; - expect(BSON.calculateObjectSize(doc)).to.equal(16); + expect(BSON.calculateObjectSize(doc)).to.equal(8 + 4 + 1 + 1 + 1 + 1); expect(BSON.calculateObjectSize(doc)).to.equal(BSON.serialize(doc).byteLength); }); }); - it('returns 0 bytes (+5 meta bytes) for a symbol value', function () { - const doc = { a: Symbol() }; - expect(BSON.calculateObjectSize(doc)).to.equal(5); - expect(BSON.calculateObjectSize(doc)).to.equal(BSON.serialize(doc).byteLength); + describe('when given a symbol value with a single character key', function () { + it('returns 0 bytes (+4 bytes for document size + 1 null terminator)', function () { + const doc = { a: Symbol() }; + expect(BSON.calculateObjectSize(doc)).to.equal(4 + 1); + expect(BSON.calculateObjectSize(doc)).to.equal(BSON.serialize(doc).byteLength); + }); }); }); From 4162eec30a095ee038598d0205aee90da51ac5f7 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Mon, 16 Dec 2024 15:29:28 -0500 Subject: [PATCH 6/9] fix: npm --- .evergreen/config.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.evergreen/config.yml b/.evergreen/config.yml index d17941bea..5abf89e8c 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -129,10 +129,9 @@ tasks: tags: ["node"] commands: - func: fetch source - vars: - NODE_LTS_VERSION: 16 - func: install dependencies vars: + NODE_LTS_VERSION: 16 NPM_VERSION: 9 - func: run tests vars: @@ -143,6 +142,7 @@ tasks: - func: fetch source vars: NODE_LTS_VERSION: 18 + NPM_VERSION: 10 - func: install dependencies - func: run tests vars: @@ -246,6 +246,7 @@ tasks: vars: # This needs to stay pinned at Node v18.16.0 for consistency across perf runs. NODE_LTS_VERSION: v18.16.0 + NPM_VERSION: 10 - func: install dependencies vars: NPM_VERSION: 9 @@ -262,6 +263,7 @@ tasks: vars: # This needs to stay pinned at Node v18.16.0 for consistency across perf runs. NODE_LTS_VERSION: v18.16.0 + NPM_VERSION: 10 - func: install dependencies vars: NPM_VERSION: 9 @@ -275,6 +277,7 @@ tasks: vars: # This needs to stay pinned at Node v18.16.0 for consistency across perf runs. NODE_LTS_VERSION: v18.16.0 + NPM_VERSION: 10 - func: install dependencies vars: NPM_VERSION: 9 From 73222e907ba41ace72566a35adf2f36c930cf478 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Mon, 16 Dec 2024 16:06:49 -0500 Subject: [PATCH 7/9] chore: fix vars --- .evergreen/config.yml | 7 +++++-- .evergreen/prepare-shell.sh | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.evergreen/config.yml b/.evergreen/config.yml index 5abf89e8c..04045e9c0 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -129,6 +129,9 @@ tasks: tags: ["node"] commands: - func: fetch source + vars: + NODE_LTS_VERSION: 16 + NPM_VERSION: 9 - func: install dependencies vars: NODE_LTS_VERSION: 16 @@ -246,7 +249,7 @@ tasks: vars: # This needs to stay pinned at Node v18.16.0 for consistency across perf runs. NODE_LTS_VERSION: v18.16.0 - NPM_VERSION: 10 + NPM_VERSION: 9 - func: install dependencies vars: NPM_VERSION: 9 @@ -263,7 +266,7 @@ tasks: vars: # This needs to stay pinned at Node v18.16.0 for consistency across perf runs. NODE_LTS_VERSION: v18.16.0 - NPM_VERSION: 10 + NPM_VERSION: 9 - func: install dependencies vars: NPM_VERSION: 9 diff --git a/.evergreen/prepare-shell.sh b/.evergreen/prepare-shell.sh index 094becbf0..ab6970d53 100644 --- a/.evergreen/prepare-shell.sh +++ b/.evergreen/prepare-shell.sh @@ -33,12 +33,14 @@ cat < expansion.yml CURRENT_VERSION: "$CURRENT_VERSION" PROJECT_DIRECTORY: "$PROJECT_DIRECTORY" NODE_LTS_VERSION: "$NODE_LTS_VERSION" +NPM_VERSION: "$NPM_VERSION" DRIVERS_TOOLS: "$DRIVERS_TOOLS" PREPARE_SHELL: | set -o errexit set -o xtrace export PROJECT_DIRECTORY="$PROJECT_DIRECTORY" export NODE_LTS_VERSION="$NODE_LTS_VERSION" + export NPM_VERSION="$NPM_VERSION" export DRIVERS_TOOLS="$DRIVERS_TOOLS" EOT # See what we've done From 2be67f040df76f73fba8b1e231a7327ad33c983e Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Tue, 17 Dec 2024 10:54:19 -0500 Subject: [PATCH 8/9] fix: npm version --- .evergreen/config.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.evergreen/config.yml b/.evergreen/config.yml index 04045e9c0..cfdc50eab 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -249,10 +249,10 @@ tasks: vars: # This needs to stay pinned at Node v18.16.0 for consistency across perf runs. NODE_LTS_VERSION: v18.16.0 - NPM_VERSION: 9 + NPM_VERSION: 10 - func: install dependencies vars: - NPM_VERSION: 9 + NPM_VERSION: 10 - func: run granular benchmarks vars: WARMUP: 1000 @@ -266,10 +266,10 @@ tasks: vars: # This needs to stay pinned at Node v18.16.0 for consistency across perf runs. NODE_LTS_VERSION: v18.16.0 - NPM_VERSION: 9 + NPM_VERSION: 10 - func: install dependencies vars: - NPM_VERSION: 9 + NPM_VERSION: 10 - func: run custom benchmarks - command: perf.send params: @@ -283,7 +283,7 @@ tasks: NPM_VERSION: 10 - func: install dependencies vars: - NPM_VERSION: 9 + NPM_VERSION: 10 - func: run spec benchmarks - command: perf.send params: From 1998da893c1bce45ce1131df9c324b6187eda250 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Tue, 17 Dec 2024 10:59:29 -0500 Subject: [PATCH 9/9] fix: npm version --- .evergreen/config.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.evergreen/config.yml b/.evergreen/config.yml index cfdc50eab..605e84044 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -249,10 +249,10 @@ tasks: vars: # This needs to stay pinned at Node v18.16.0 for consistency across perf runs. NODE_LTS_VERSION: v18.16.0 - NPM_VERSION: 10 + NPM_VERSION: 9 - func: install dependencies vars: - NPM_VERSION: 10 + NPM_VERSION: 9 - func: run granular benchmarks vars: WARMUP: 1000 @@ -266,10 +266,10 @@ tasks: vars: # This needs to stay pinned at Node v18.16.0 for consistency across perf runs. NODE_LTS_VERSION: v18.16.0 - NPM_VERSION: 10 + NPM_VERSION: 9 - func: install dependencies vars: - NPM_VERSION: 10 + NPM_VERSION: 9 - func: run custom benchmarks - command: perf.send params: @@ -280,10 +280,10 @@ tasks: vars: # This needs to stay pinned at Node v18.16.0 for consistency across perf runs. NODE_LTS_VERSION: v18.16.0 - NPM_VERSION: 10 + NPM_VERSION: 9 - func: install dependencies vars: - NPM_VERSION: 10 + NPM_VERSION: 9 - func: run spec benchmarks - command: perf.send params: