From bb52e8d0c153a0a82392437f7fc1b7d5465ceccb Mon Sep 17 00:00:00 2001 From: Daria Pardue Date: Thu, 2 Dec 2021 16:14:25 -0500 Subject: [PATCH 1/9] refactor(NODE-3717): move crud spec tests to integration --- .../crud_spec.test.js => integration/crud/crud.spec.test.js} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename test/{functional/crud_spec.test.js => integration/crud/crud.spec.test.js} (99%) diff --git a/test/functional/crud_spec.test.js b/test/integration/crud/crud.spec.test.js similarity index 99% rename from test/functional/crud_spec.test.js rename to test/integration/crud/crud.spec.test.js index 4e2b8e27822..c37d39e5650 100644 --- a/test/functional/crud_spec.test.js +++ b/test/integration/crud/crud.spec.test.js @@ -6,8 +6,8 @@ const chai = require('chai'); const expect = chai.expect; chai.use(require('chai-subset')); -const { loadSpecTests } = require('../spec/index'); -const { runUnifiedTest } = require('../tools/unified-spec-runner/runner'); +const { loadSpecTests } = require('../../spec/index'); +const { runUnifiedTest } = require('../../tools/unified-spec-runner/runner'); function enforceServerVersionLimits(requires, scenario) { const versionLimits = []; From 049048193e13d90cfce0bfd20d22f10844897bf2 Mon Sep 17 00:00:00 2001 From: Daria Pardue Date: Thu, 2 Dec 2021 16:20:04 -0500 Subject: [PATCH 2/9] refactor: move crud driver tests to integration --- test/{functional => integration/crud}/crud_api.test.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) rename test/{functional => integration/crud}/crud_api.test.js (99%) diff --git a/test/functional/crud_api.test.js b/test/integration/crud/crud_api.test.js similarity index 99% rename from test/functional/crud_api.test.js rename to test/integration/crud/crud_api.test.js index 29a5d4f3e86..3138c355370 100644 --- a/test/functional/crud_api.test.js +++ b/test/integration/crud/crud_api.test.js @@ -1,8 +1,7 @@ 'use strict'; -const test = require('./shared').assert; +const { assert: test, setupDatabase } = require('../shared'); const { expect } = require('chai'); -const { ReturnDocument, ObjectId } = require('../../src'); -const setupDatabase = require('./shared').setupDatabase; +const { ReturnDocument, ObjectId } = require('../../../src'); // instanceof cannot be use reliably to detect the new models in js due to scoping and new // contexts killing class info find/distinct/count thus cannot be overloaded without breaking From e406acef24b10a4a20271228cc724015ebced4ea Mon Sep 17 00:00:00 2001 From: Daria Pardue Date: Thu, 2 Dec 2021 16:43:53 -0500 Subject: [PATCH 3/9] test: fix spec directory path --- test/integration/crud/crud.spec.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/crud/crud.spec.test.js b/test/integration/crud/crud.spec.test.js index c37d39e5650..8311c270285 100644 --- a/test/integration/crud/crud.spec.test.js +++ b/test/integration/crud/crud.spec.test.js @@ -26,7 +26,7 @@ function enforceServerVersionLimits(requires, scenario) { } function findScenarios() { - const route = [__dirname, '..', 'spec', 'crud'].concat(Array.from(arguments)); + const route = [__dirname, '..', '..', 'spec', 'crud'].concat(Array.from(arguments)); return fs .readdirSync(path.resolve.apply(path, route)) .filter(x => x.indexOf('json') !== -1) From 01aae675b624a29c9b5578ff471cffb99cfd83b4 Mon Sep 17 00:00:00 2001 From: Daria Pardue Date: Thu, 2 Dec 2021 17:04:26 -0500 Subject: [PATCH 4/9] refactor: move max staleness test to integration directory --- .../max-staleness}/max_staleness.test.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) rename test/{functional => integration/max-staleness}/max_staleness.test.js (97%) diff --git a/test/functional/max_staleness.test.js b/test/integration/max-staleness/max_staleness.test.js similarity index 97% rename from test/functional/max_staleness.test.js rename to test/integration/max-staleness/max_staleness.test.js index cdbacb800a6..2edd6a29e5e 100644 --- a/test/functional/max_staleness.test.js +++ b/test/integration/max-staleness/max_staleness.test.js @@ -1,10 +1,11 @@ 'use strict'; const { Long } = require('bson'); const { expect } = require('chai'); -const mock = require('../tools/mock'); -const { ReadPreference } = require('../../src'); +const mock = require('../../tools/mock'); +const { ReadPreference } = require('../../../src'); const test = {}; +// TODO (NODE-3799): convert these to run against a real server describe('Max Staleness', function () { afterEach(() => mock.cleanup()); beforeEach(() => { From 6b775d2d66b4961cec161b9a6fd1638f0ac1ad0f Mon Sep 17 00:00:00 2001 From: Daria Pardue Date: Thu, 2 Dec 2021 17:23:52 -0500 Subject: [PATCH 5/9] refactor: move bulk tests into integration/crud and separate prose test --- .../crud}/bulk.test.js | 51 ++----------------- test/integration/crud/crud.prose.test.js | 43 ++++++++++++++++ 2 files changed, 47 insertions(+), 47 deletions(-) rename test/{functional => integration/crud}/bulk.test.js (97%) create mode 100644 test/integration/crud/crud.prose.test.js diff --git a/test/functional/bulk.test.js b/test/integration/crud/bulk.test.js similarity index 97% rename from test/functional/bulk.test.js rename to test/integration/crud/bulk.test.js index 72151081ea3..0616f7edbaf 100644 --- a/test/functional/bulk.test.js +++ b/test/integration/crud/bulk.test.js @@ -4,11 +4,10 @@ const { withClientV2, withMonitoredClient, setupDatabase, - ignoreNsNotFound -} = require('./shared'); -const test = require('./shared').assert; -const { MongoDriverError, MongoBatchReExecutionError } = require('../../src/error'); -const { Long, MongoBulkWriteError } = require('../../src'); + ignoreNsNotFound, + assert: test +} = require('../shared'); +const { Long, MongoBatchReExecutionError, MongoDriverError } = require('../../../src'); const crypto = require('crypto'); const chai = require('chai'); const expect = chai.expect; @@ -21,48 +20,6 @@ describe('Bulk', function () { return setupDatabase(this.configuration); }); - describe('Write Errors', () => { - describe('errInfo property on insertMany', () => { - let client; - - beforeEach(async function () { - client = this.configuration.newClient({ monitorCommands: true }); - await client.connect(); - }); - - afterEach(async () => { - if (client) { - await client.close(); - } - }); - - it('should be accessible', { - metadata: { requires: { mongodb: '>=5.0.0' } }, - async test() { - try { - await client.db().collection('wc_details').drop(); - } catch { - // don't care - } - - const collection = await client - .db() - .createCollection('wc_details', { validator: { x: { $type: 'string' } } }); - - try { - await collection.insertMany([{ x: /not a string/ }]); - expect.fail('The insert should fail the validation that x must be a string'); - } catch (error) { - expect(error).to.be.instanceOf(MongoBulkWriteError); - expect(error).to.have.property('code', 121); - expect(error).to.have.property('writeErrors').that.is.an('array'); - expect(error.writeErrors[0]).to.have.property('errInfo').that.is.an('object'); - } - } - }); - }); - }); - it('should correctly handle ordered single batch api write command error', { metadata: { requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } diff --git a/test/integration/crud/crud.prose.test.js b/test/integration/crud/crud.prose.test.js new file mode 100644 index 00000000000..7b1cae26aa2 --- /dev/null +++ b/test/integration/crud/crud.prose.test.js @@ -0,0 +1,43 @@ +const { expect } = require('chai'); +const { MongoBulkWriteError } = require('../../../src'); + +describe('CRUD Prose Spec Tests', () => { + let client; + + beforeEach(async function () { + client = this.configuration.newClient({ monitorCommands: true }); + await client.connect(); + }); + + afterEach(async () => { + if (client) { + await client.close(); + } + }); + + // Note: This test does not fully implement the described test, it's missing command monitoring assertions + it('2. WriteError.details exposes writeErrors[].errInfo', { + metadata: { requires: { mongodb: '>=5.0.0' } }, + async test() { + try { + await client.db().collection('wc_details').drop(); + } catch { + // don't care + } + + const collection = await client + .db() + .createCollection('wc_details', { validator: { x: { $type: 'string' } } }); + + try { + await collection.insertMany([{ x: /not a string/ }]); + expect.fail('The insert should fail the validation that x must be a string'); + } catch (error) { + expect(error).to.be.instanceOf(MongoBulkWriteError); + expect(error).to.have.property('code', 121); + expect(error).to.have.property('writeErrors').that.is.an('array'); + expect(error.writeErrors[0]).to.have.property('errInfo').that.is.an('object'); + } + } + }); +}); From 4094c8745e567cd70f3882285a7bb77d580fc13d Mon Sep 17 00:00:00 2001 From: Daria Pardue Date: Thu, 2 Dec 2021 17:41:08 -0500 Subject: [PATCH 6/9] refactor: move load balancer spec tests to integration --- .evergreen/run-serverless-tests.sh | 4 ++-- .../load-balancers/load_balancers.spec.test.js} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename test/{functional/load-balancer-spec.test.js => integration/load-balancers/load_balancers.spec.test.js} (95%) diff --git a/.evergreen/run-serverless-tests.sh b/.evergreen/run-serverless-tests.sh index 619e89eaa76..9868babf2b1 100644 --- a/.evergreen/run-serverless-tests.sh +++ b/.evergreen/run-serverless-tests.sh @@ -12,10 +12,10 @@ if [ -z ${SERVERLESS_ATLAS_USER+omitted} ]; then echo "SERVERLESS_ATLAS_USER is if [ -z ${SERVERLESS_ATLAS_PASSWORD+omitted} ]; then echo "SERVERLESS_ATLAS_PASSWORD is unset" && exit 1; fi npx mocha --file test/tools/runner/index.js \ - test/functional/crud_spec.test.js \ + test/integration/crud/crud.spec.test.js \ test/functional/retryable_reads.test.js \ test/functional/retryable_writes.test.js \ test/functional/sessions.test.js \ test/functional/transactions.test.js \ test/functional/versioned-api.test.js \ - test/functional/load-balancer-spec.test.js + test/integration/load-balancers/load_balancers.spec.test.js diff --git a/test/functional/load-balancer-spec.test.js b/test/integration/load-balancers/load_balancers.spec.test.js similarity index 95% rename from test/functional/load-balancer-spec.test.js rename to test/integration/load-balancers/load_balancers.spec.test.js index 75addc38f5d..22835bec7ab 100644 --- a/test/functional/load-balancer-spec.test.js +++ b/test/integration/load-balancers/load_balancers.spec.test.js @@ -1,7 +1,7 @@ 'use strict'; const path = require('path'); -const { loadSpecTests } = require('../spec/index'); -const { runUnifiedSuite } = require('../tools/unified-spec-runner/runner'); +const { loadSpecTests } = require('../../spec/index'); +const { runUnifiedSuite } = require('../../tools/unified-spec-runner/runner'); const SKIP = [ // Verified they use the same connection but the Node implementation executes From baf179c2f4bb03ccb331ace5d50ab96cad431506 Mon Sep 17 00:00:00 2001 From: Daria Pardue Date: Thu, 2 Dec 2021 17:57:03 -0500 Subject: [PATCH 7/9] refactor: move retryable reads tests to integration --- .evergreen/run-serverless-tests.sh | 2 +- .../retryable-reads/retryable_reads.spec.test.js} | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) rename test/{functional/retryable_reads.test.js => integration/retryable-reads/retryable_reads.spec.test.js} (82%) diff --git a/.evergreen/run-serverless-tests.sh b/.evergreen/run-serverless-tests.sh index 9868babf2b1..37d43661a2b 100644 --- a/.evergreen/run-serverless-tests.sh +++ b/.evergreen/run-serverless-tests.sh @@ -13,7 +13,7 @@ if [ -z ${SERVERLESS_ATLAS_PASSWORD+omitted} ]; then echo "SERVERLESS_ATLAS_PASS npx mocha --file test/tools/runner/index.js \ test/integration/crud/crud.spec.test.js \ - test/functional/retryable_reads.test.js \ + test/integration/retryable-reads/retryable_reads.spec.test.js \ test/functional/retryable_writes.test.js \ test/functional/sessions.test.js \ test/functional/transactions.test.js \ diff --git a/test/functional/retryable_reads.test.js b/test/integration/retryable-reads/retryable_reads.spec.test.js similarity index 82% rename from test/functional/retryable_reads.test.js rename to test/integration/retryable-reads/retryable_reads.spec.test.js index 3ea97a648ff..48206cb648a 100644 --- a/test/functional/retryable_reads.test.js +++ b/test/integration/retryable-reads/retryable_reads.spec.test.js @@ -1,8 +1,7 @@ 'use strict'; -const TestRunnerContext = require('./spec-runner').TestRunnerContext; -const generateTopologyTests = require('./spec-runner').generateTopologyTests; -const loadSpecTests = require('../spec').loadSpecTests; +const { TestRunnerContext, generateTopologyTests } = require('../../tools/spec-runner'); +const { loadSpecTests } = require('../../spec'); describe('Retryable Reads', function () { const testContext = new TestRunnerContext(); From f826dab3bc36ab193547bc19cbae683d3b89aae9 Mon Sep 17 00:00:00 2001 From: Daria Pardue Date: Thu, 2 Dec 2021 18:03:09 -0500 Subject: [PATCH 8/9] refactor: move retryable writes tests to integration --- .evergreen/run-serverless-tests.sh | 2 +- .../retryable-writes/retryable_writes.spec.test.js} | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) rename test/{functional/retryable_writes.test.js => integration/retryable-writes/retryable_writes.spec.test.js} (97%) diff --git a/.evergreen/run-serverless-tests.sh b/.evergreen/run-serverless-tests.sh index 37d43661a2b..e104fb5a2fe 100644 --- a/.evergreen/run-serverless-tests.sh +++ b/.evergreen/run-serverless-tests.sh @@ -14,7 +14,7 @@ if [ -z ${SERVERLESS_ATLAS_PASSWORD+omitted} ]; then echo "SERVERLESS_ATLAS_PASS npx mocha --file test/tools/runner/index.js \ test/integration/crud/crud.spec.test.js \ test/integration/retryable-reads/retryable_reads.spec.test.js \ - test/functional/retryable_writes.test.js \ + test/integration/retryable-writes/retryable_writes.spec.test.js \ test/functional/sessions.test.js \ test/functional/transactions.test.js \ test/functional/versioned-api.test.js \ diff --git a/test/functional/retryable_writes.test.js b/test/integration/retryable-writes/retryable_writes.spec.test.js similarity index 97% rename from test/functional/retryable_writes.test.js rename to test/integration/retryable-writes/retryable_writes.spec.test.js index 571bc75f32c..5cb797b0b9b 100644 --- a/test/functional/retryable_writes.test.js +++ b/test/integration/retryable-writes/retryable_writes.spec.test.js @@ -1,8 +1,8 @@ 'use strict'; -const expect = require('chai').expect; -const loadSpecTests = require('../spec').loadSpecTests; -const parseRunOn = require('../functional/spec-runner').parseRunOn; +const { expect } = require('chai'); +const { loadSpecTests } = require('../../spec'); +const { parseRunOn } = require('../../tools/spec-runner'); describe('Retryable Writes', function () { let ctx = {}; From 8a9f700cfcbce7480abe0566aeada298df341164 Mon Sep 17 00:00:00 2001 From: Daria Pardue Date: Thu, 2 Dec 2021 18:20:46 -0500 Subject: [PATCH 9/9] refactor: move versioned api test to integration --- .evergreen/run-serverless-tests.sh | 2 +- .../versioned-api/versioned_api.spec.test.js} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename test/{functional/versioned-api.test.js => integration/versioned-api/versioned_api.spec.test.js} (87%) diff --git a/.evergreen/run-serverless-tests.sh b/.evergreen/run-serverless-tests.sh index e104fb5a2fe..069cce6e137 100644 --- a/.evergreen/run-serverless-tests.sh +++ b/.evergreen/run-serverless-tests.sh @@ -17,5 +17,5 @@ npx mocha --file test/tools/runner/index.js \ test/integration/retryable-writes/retryable_writes.spec.test.js \ test/functional/sessions.test.js \ test/functional/transactions.test.js \ - test/functional/versioned-api.test.js \ + test/integration/versioned-api/versioned_api.spec.test.js \ test/integration/load-balancers/load_balancers.spec.test.js diff --git a/test/functional/versioned-api.test.js b/test/integration/versioned-api/versioned_api.spec.test.js similarity index 87% rename from test/functional/versioned-api.test.js rename to test/integration/versioned-api/versioned_api.spec.test.js index fffc0c29cf4..83f1ddff54e 100644 --- a/test/functional/versioned-api.test.js +++ b/test/integration/versioned-api/versioned_api.spec.test.js @@ -1,8 +1,8 @@ 'use strict'; const { expect } = require('chai'); -const { loadSpecTests } = require('../spec/index'); -const { runUnifiedTest } = require('../tools/unified-spec-runner/runner'); +const { loadSpecTests } = require('../../spec/'); +const { runUnifiedTest } = require('../../tools/unified-spec-runner/runner'); describe('Versioned API', function () { it('should throw an error if serverApi version is provided via the uri', {