Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
5 changes: 4 additions & 1 deletion test/integration/change-streams/change_streams.spec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import * as path from 'path';
import { loadSpecTests } from '../../spec';
import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';

// TODO: NODE-7559 - remove the mongodb version requirement once the spec tests are updated to be compatible with MongoDB 9.0
describe('Change Streams Spec - Unified', function () {
runUnifiedSuite(loadSpecTests(path.join('change-streams', 'unified')));
it('should run, unless it should not', { requires: { mongodb: '<9.0' } }, function () {
Copy link
Copy Markdown
Member

@tadjik1 tadjik1 May 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one fundamental problem with this approach, caused by 2 independent causes:
describe (which is created by runUnifiedSuite) is ignored when defined inside it (introduced by this change), so you can see on evergreen logs like this:

[2026/05/02 03:55:27.933]   Change Streams Spec - Unified
[2026/05/02 03:55:27.933]     ✔ should run, unless it should not
[2026/05/02 03:55:28.266]   Client Backpressure (Prose)
[2026/05/02 03:55:28.266]     ✔ Test 1: Operation Retry Uses Exponential Backoff (325ms)
[2026/05/02 03:55:28.536]     ✔ Test 3: Overload Errors are Retried a Maximum of MAX_RETRIES times (259ms)
[2026/05/02 03:55:28.584]     ✔ Test 4: Overload Errors are Retried a Maximum of maxAdaptiveRetries times when configured

Basically it means no tests are running. But then there a second problem I want to highlight: in our current configuration the matrix looks like:

const MONGODB_VERSIONS = ['latest', 'rapid', '8.0', '7.0', '6.0', '5.0', '4.4', '4.2'];

Which means (with the constraints down below mongodb: '>=8.2.0 <9.0.0')we don't run tests on 8.1, 8.2, etc. The only variant we catch - is rapid, just because it's 8.3 currently. In other words we do not run tests on latest stable release which is 8.2.7 at the moment.

Can you please take a look into this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! PR updated, here are the new results:

The explanation is actually more complicated than MONGODB_VERSIONS.
(MONGODB_VERSIONS is only used to build the jobs. rapid results in the latest 8 version, while latest pulls in 9.0.0-alpha..., I don't think it's related to this at all.)

The last version was:

it('should run, unless it should not', { requires: { mongodb: '<9.0' } }, function () {
  runUnifiedSuite(loadSpecTests(...));
});

When MDB was < 9.0: Mocha runs the it callback, runUnifiedSuite tries to register test blocks during test execution, which Mocha silently drops. The outer it passes with zero assertions, giving us a false green. The change stream spec tests never run.
When MDB was >= 9.0: Mocha's requires check filters out the outer it: same thing, tests don't run.

New code:

describe('Change Streams Spec - Unified', function () {
  runUnifiedSuite(loadSpecTests(...), (_test, ctx) =>
    gte(ctx.version, '9.0.0') ? 'TODO(NODE-7559): ...' : false
  );
});

When MDB < 9.0: runUnifiedSuite called synchronously inside describe, so all nested/new context/it blocks register correctly during suite construction. Mocha then executes them normally.
When MDB >= 9.0: same new blocks are registered, then as each it executes, the skipFilter returns a skip reason string, and Mocha marks that individual test as skipped due to NODE-7559.

runUnifiedSuite(loadSpecTests(path.join('change-streams', 'unified')));
});
Comment thread
PavelSafronov marked this conversation as resolved.
Outdated
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ const metadata: MongoDBMetadataUI = {
libmongocrypt: '>=1.15.1'
}
};
// # Server 9.0.0-rc0 removes support for "prefixPreview" and "suffixPreview": SERVER-123416
const metadataWithoutPreview: MongoDBMetadataUI = {
requires: {
clientSideEncryption: '>=6.4.0',
mongodb: '>=8.2.0 <9.0.0',
topology: '!single',
libmongocrypt: '>=1.15.1'
}
};

const loadFLEDataFile = async (filename: string) =>
EJSON.parse(
Expand All @@ -33,9 +42,12 @@ describe('27. Text Explicit Encryption', function () {

beforeEach(async function () {
utilClient = this.configuration.newClient();
const isServer9OrAbove = this.configuration.version >= '9.0.0';
const shouldRunPrefixSuffixTests = !isServer9OrAbove;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, using semver.


// Using QE CreateCollection() and Collection.Drop(), drop and create the following collections with majority write concern:
// - db.prefix-suffix using the encryptedFields option set to the contents of encryptedFields-prefix-suffix.json
// Skip this step if testing server 9.0.0+.
// - db.substring using the encryptedFields option set to the contents of encryptedFields-substring.json
async function dropAndCreateCollection(ns: string, encryptedFields?: Document) {
const { db, collection } = MongoDBCollectionNamespace.fromString(ns);
Expand All @@ -49,10 +61,12 @@ describe('27. Text Explicit Encryption', function () {
});
}

await dropAndCreateCollection(
'db.prefix-suffix',
await loadFLEDataFile('encryptedFields-prefix-suffix.json')
);
if (shouldRunPrefixSuffixTests) {
await dropAndCreateCollection(
'db.prefix-suffix',
await loadFLEDataFile('encryptedFields-prefix-suffix.json')
);
}
await dropAndCreateCollection(
'db.substring',
await loadFLEDataFile('encryptedFields-substring.json')
Expand Down Expand Up @@ -144,18 +158,20 @@ describe('27. Text Explicit Encryption', function () {
}
});

// Use `encryptedClient` to insert the following document into `db.prefix-suffix` with majority write concern:
// { "_id": 0, "encryptedText": <encrypted 'foobarbaz'> }
await encryptedClient
.db('db')
.collection<{ _id: number; encryptedText: Binary }>('prefix-suffix')
.insertOne(
{
_id: 0,
encryptedText
},
{ writeConcern: { w: 'majority' } }
);
if (shouldRunPrefixSuffixTests) {
// Use `encryptedClient` to insert the following document into `db.prefix-suffix` with majority write concern:
// { "_id": 0, "encryptedText": <encrypted 'foobarbaz'> }
await encryptedClient
.db('db')
.collection<{ _id: number; encryptedText: Binary }>('prefix-suffix')
.insertOne(
{
_id: 0,
encryptedText
},
{ writeConcern: { w: 'majority' } }
);
}
}

{
Expand Down Expand Up @@ -208,7 +224,8 @@ describe('27. Text Explicit Encryption', function () {
await Promise.allSettled([utilClient.close(), encryptedClient.close(), keyVaultClient.close()]);
});

it('Case 1: can find a document by prefix', metadata, async function () {
it('Case 1: can find a document by prefix', metadataWithoutPreview, async function () {
// Skip this test case if testing MongoDB server 9.0.0+.
// Use clientEncryption.encrypt() to encrypt the string "foo" with the following EncryptOpts:
// class EncryptOpts {
// keyId : <key1ID>,
Expand Down Expand Up @@ -260,7 +277,8 @@ describe('27. Text Explicit Encryption', function () {
expect(result).to.deep.equal({ _id: 0, encryptedText: 'foobarbaz' });
});

it('Case 2: can find a document by suffix', metadata, async function () {
it('Case 2: can find a document by suffix', metadataWithoutPreview, async function () {
// Skip this test case if testing MongoDB server 9.0.0+.
// Use clientEncryption.encrypt() to encrypt the string "baz" with the following EncryptOpts:
// class EncryptOpts {
// keyId : <key1ID>,
Expand Down Expand Up @@ -311,7 +329,8 @@ describe('27. Text Explicit Encryption', function () {
expect(result).to.deep.equal({ _id: 0, encryptedText: 'foobarbaz' });
});

it('Case 3: assert no document found by prefix', metadata, async function () {
it('Case 3: assert no document found by prefix', metadataWithoutPreview, async function () {
// Skip this test case if testing MongoDB server 9.0.0+.
// Use clientEncryption.encrypt() to encrypt the string "baz" with the following EncryptOpts:
// class EncryptOpts {
// keyId : <key1ID>,
Expand Down Expand Up @@ -351,7 +370,8 @@ describe('27. Text Explicit Encryption', function () {
expect(await encryptedClient.db('db').collection('prefix-suffix').findOne(filter)).to.be.null;
});

it('Case 4: assert no document found by suffix', metadata, async function () {
it('Case 4: assert no document found by suffix', metadataWithoutPreview, async function () {
// Skip this test case if testing MongoDB server 9.0.0+.
// Use clientEncryption.encrypt() to encrypt the string "foo" with the following EncryptOpts:
// class EncryptOpts {
// keyId : <key1ID>,
Expand Down Expand Up @@ -497,7 +517,8 @@ describe('27. Text Explicit Encryption', function () {
expect(result).to.be.null;
});

it('Case 7: assert contentionFactor is required', metadata, async function () {
it('Case 7: assert contentionFactor is required', metadataWithoutPreview, async function () {
// Skip this test case if testing MongoDB server 9.0.0+.
// Use clientEncryption.encrypt() to encrypt the string "foo" with the following EncryptOpts:
// class EncryptOpts {
// keyId : <key1ID>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"runOnRequirements": [
{
"minServerVersion": "8.2.0",
"maxServerVersion": "8.99.99",
"topologies": [
"replicaset",
"sharded",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ description: QE-Text-cleanupStructuredEncryptionData
schemaVersion: "1.25"
runOnRequirements:
- minServerVersion: "8.2.0" # Server 8.2.0 adds preview support for QE text queries.
maxServerVersion: "8.99.99" # Server 9.0.0-rc0 removes support for "prefixPreview" and "suffixPreview": SERVER-123416
topologies: ["replicaset", "sharded", "load-balanced"] # QE does not support standalone.
csfle:
minLibmongocryptVersion: 1.15.0 # For SPM-4158.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"runOnRequirements": [
{
"minServerVersion": "8.2.0",
"maxServerVersion": "8.99.99",
"topologies": [
"replicaset",
"sharded",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ description: QE-Text-compactStructuredEncryptionData
schemaVersion: "1.25"
runOnRequirements:
- minServerVersion: "8.2.0" # Server 8.2.0 adds preview support for QE text queries.
maxServerVersion: "8.99.99" # Server 9.0.0-rc0 removes support for "prefixPreview" and "suffixPreview": SERVER-123416
topologies: ["replicaset", "sharded", "load-balanced"] # QE does not support standalone.
csfle:
minLibmongocryptVersion: 1.15.0 # For SPM-4158.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"runOnRequirements": [
{
"minServerVersion": "8.2.0",
"maxServerVersion": "8.99.99",
"topologies": [
"replicaset",
"sharded",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ description: QE-Text-prefixPreview
schemaVersion: "1.25"
runOnRequirements:
- minServerVersion: "8.2.0" # Server 8.2.0 adds preview support for QE text queries.
maxServerVersion: "8.99.99" # Server 9.0.0-rc0 removes support for "prefixPreview" and "suffixPreview": SERVER-123416
topologies: ["replicaset", "sharded", "load-balanced"] # QE does not support standalone.
csfle:
minLibmongocryptVersion: 1.15.0 # For SPM-4158.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
],
"tests": [
{
"description": "Insert QE suffixPreview",
"description": "Insert QE substringPreview",
"operations": [
{
"name": "insertOne",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ initialData:
],
}
tests:
- description: "Insert QE suffixPreview"
- description: "Insert QE substringPreview"
operations:
- name: insertOne
arguments:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"runOnRequirements": [
{
"minServerVersion": "8.2.0",
"maxServerVersion": "8.99.99",
"topologies": [
"replicaset",
"sharded",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ description: QE-Text-suffixPreview
schemaVersion: "1.25"
runOnRequirements:
- minServerVersion: "8.2.0" # Server 8.2.0 adds preview support for QE text queries.
maxServerVersion: "8.99.99" # Server 9.0.0-rc0 removes support for "prefixPreview" and "suffixPreview": SERVER-123416
topologies: ["replicaset", "sharded", "load-balanced"] # QE does not support standalone.
csfle:
minLibmongocryptVersion: 1.15.0 # For SPM-4158.
Expand Down
Loading