Skip to content

Commit bc70022

Browse files
authored
test(NODE-4323): add a unit test task with bson-ext installed (#3347)
1 parent 6f5241f commit bc70022

File tree

7 files changed

+268
-98
lines changed

7 files changed

+268
-98
lines changed

.evergreen/config.in.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -837,15 +837,19 @@ functions:
837837
- "${PROJECT_DIRECTORY}/.evergreen/run-snappy-version-test.sh"
838838

839839
"run bson-ext test":
840-
- command: shell.exec
840+
- command: subprocess.exec
841841
type: test
842842
params:
843843
working_dir: "src"
844844
timeout_secs: 60
845-
script: |
846-
${PREPARE_SHELL}
845+
env:
846+
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
847+
MONGODB_URI: ${MONGODB_URI}
848+
TEST_NPM_SCRIPT: ${TEST_NPM_SCRIPT}
849+
binary: bash
850+
args:
851+
- '${PROJECT_DIRECTORY}/.evergreen/run-bson-ext-test.sh'
847852

848-
MONGODB_URI="${MONGODB_URI}" bash ${PROJECT_DIRECTORY}/.evergreen/run-bson-ext-test.sh
849853

850854
"upload test results":
851855
# Upload the xunit-format test results.

.evergreen/config.yml

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -800,15 +800,18 @@ functions:
800800
args:
801801
- ${PROJECT_DIRECTORY}/.evergreen/run-snappy-version-test.sh
802802
run bson-ext test:
803-
- command: shell.exec
803+
- command: subprocess.exec
804804
type: test
805805
params:
806806
working_dir: src
807807
timeout_secs: 60
808-
script: |
809-
${PREPARE_SHELL}
810-
811-
MONGODB_URI="${MONGODB_URI}" bash ${PROJECT_DIRECTORY}/.evergreen/run-bson-ext-test.sh
808+
env:
809+
PROJECT_DIRECTORY: ${PROJECT_DIRECTORY}
810+
MONGODB_URI: ${MONGODB_URI}
811+
TEST_NPM_SCRIPT: ${TEST_NPM_SCRIPT}
812+
binary: bash
813+
args:
814+
- ${PROJECT_DIRECTORY}/.evergreen/run-bson-ext-test.sh
812815
upload test results:
813816
- command: attach.xunit_results
814817
params:
@@ -1671,8 +1674,26 @@ tasks:
16711674
VERSION: '5.0'
16721675
TOPOLOGY: server
16731676
AUTH: auth
1674-
- func: run custom snappy tests
1675-
- name: run-bson-ext-test
1677+
- name: run-custom-snappy-tests
1678+
func: run custom snappy tests
1679+
- name: run-bson-ext-integration
1680+
tags:
1681+
- run-custom-dependency-tests
1682+
commands:
1683+
- func: install dependencies
1684+
vars:
1685+
NODE_LTS_NAME: erbium
1686+
- func: bootstrap mongo-orchestration
1687+
vars:
1688+
VERSION: '5.0'
1689+
TOPOLOGY: server
1690+
AUTH: auth
1691+
- name: run-bson-ext-integration
1692+
func: run bson-ext test
1693+
vars:
1694+
NODE_LTS_NAME: erbium
1695+
TEST_NPM_SCRIPT: check:test
1696+
- name: run-bson-ext-unit
16761697
tags:
16771698
- run-custom-dependency-tests
16781699
commands:
@@ -1684,9 +1705,11 @@ tasks:
16841705
VERSION: '5.0'
16851706
TOPOLOGY: server
16861707
AUTH: auth
1687-
- func: run bson-ext test
1708+
- name: run-bson-ext-unit
1709+
func: run bson-ext test
16881710
vars:
16891711
NODE_LTS_NAME: erbium
1712+
TEST_NPM_SCRIPT: check:unit
16901713
- name: run-custom-csfle-tests-mongocryptd-pinned-commit
16911714
tags:
16921715
- run-custom-dependency-tests
@@ -2308,7 +2331,8 @@ buildvariants:
23082331
run_on: ubuntu1804-large
23092332
tasks:
23102333
- run-custom-snappy-tests
2311-
- run-bson-ext-test
2334+
- run-bson-ext-integration
2335+
- run-bson-ext-unit
23122336
- run-custom-csfle-tests-mongocryptd-pinned-commit
23132337
- run-custom-csfle-tests-mongocryptd-master
23142338
- run-custom-csfle-shared-lib-tests-pinned-commit

.evergreen/generate_evergreen_tasks.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const yaml = require('js-yaml');
55
const LATEST_EFFECTIVE_VERSION = '6.0';
66
const MONGODB_VERSIONS = ['latest', '6.0', '5.0', '4.4', '4.2', '4.0', '3.6'];
77
const NODE_VERSIONS = ['erbium', 'fermium', 'gallium'];
8-
NODE_VERSIONS.sort()
8+
NODE_VERSIONS.sort();
99
const LOWEST_LTS = NODE_VERSIONS[0];
1010

1111
const TOPOLOGIES = ['server', 'replica_set', 'sharded_cluster'];
@@ -136,7 +136,7 @@ TASKS.push(
136136
VERSION: '5.0',
137137
TOPOLOGY: 'sharded_cluster',
138138
AUTH: 'auth',
139-
LOAD_BALANCER: 'true',
139+
LOAD_BALANCER: 'true'
140140
}
141141
},
142142
{ func: 'start-load-balancer' },
@@ -155,7 +155,7 @@ TASKS.push(
155155
VERSION: '6.0',
156156
TOPOLOGY: 'sharded_cluster',
157157
AUTH: 'auth',
158-
LOAD_BALANCER: 'true',
158+
LOAD_BALANCER: 'true'
159159
}
160160
},
161161
{ func: 'start-load-balancer' },
@@ -505,17 +505,30 @@ BUILD_VARIANTS.push({
505505
});
506506

507507
const oneOffFuncs = [
508-
{ func: 'run custom snappy tests' },
509508
{
509+
name: 'run-custom-snappy-tests',
510+
func: 'run custom snappy tests'
511+
},
512+
{
513+
name: 'run-bson-ext-integration',
514+
func: 'run bson-ext test',
515+
vars: {
516+
NODE_LTS_NAME: LOWEST_LTS,
517+
TEST_NPM_SCRIPT: 'check:test'
518+
}
519+
},
520+
{
521+
name: 'run-bson-ext-unit',
510522
func: 'run bson-ext test',
511523
vars: {
512-
NODE_LTS_NAME: LOWEST_LTS
524+
NODE_LTS_NAME: LOWEST_LTS,
525+
TEST_NPM_SCRIPT: 'check:unit'
513526
}
514527
}
515528
];
516529

517530
const oneOffFuncAsTasks = oneOffFuncs.map(oneOffFunc => ({
518-
name: `${oneOffFunc.func.split(' ').join('-')}`,
531+
name: oneOffFunc.name,
519532
tags: ['run-custom-dependency-tests'],
520533
commands: [
521534
{

test/integration/node-specific/bson-options/utf8_validation.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ describe('class BinMsg', () => {
2121
});
2222

2323
afterEach(() => {
24-
deserializeSpy.restore();
24+
deserializeSpy?.restore();
25+
// @ts-expect-error: Allow this to be garbage collected
2526
deserializeSpy = null;
2627
});
2728

test/tools/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,3 +489,10 @@ export class UnifiedTestSuiteBuilder {
489489
return JSON.parse(JSON.stringify(this));
490490
}
491491
}
492+
493+
/** Test whether the driver is using bson-ext */
494+
export function isBSONExtImported() {
495+
// eslint-disable-next-line @typescript-eslint/no-var-requires
496+
const driverBSON = require('../../src/bson');
497+
return driverBSON.deserialize.toString().includes('[native code]');
498+
}

test/unit/bson.test.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,7 @@
22

33
const { expect } = require('chai');
44
const BSON = require('../../src/bson');
5-
6-
function isBSONExtInstalled() {
7-
try {
8-
require.resolve('bson-ext');
9-
return true;
10-
} catch (_) {
11-
return false;
12-
}
13-
}
5+
const { isBSONExtImported } = require('../tools/utils');
146

157
describe('When importing BSON', function () {
168
const types = [
@@ -57,7 +49,7 @@ describe('When importing BSON', function () {
5749

5850
describe('bson-ext', function () {
5951
before(function () {
60-
if (!isBSONExtInstalled()) {
52+
if (!isBSONExtImported()) {
6153
this.skip();
6254
}
6355
});
@@ -73,7 +65,7 @@ describe('When importing BSON', function () {
7365

7466
describe('js-bson', function () {
7567
before(function () {
76-
if (isBSONExtInstalled()) {
68+
if (isBSONExtImported()) {
7769
this.skip();
7870
}
7971
});

0 commit comments

Comments
 (0)