Skip to content

Commit 21d90ad

Browse files
Merge branch 'main' into NODE-5988/6.x-raw-results-doc-MongoServerError
2 parents 8e33665 + e30c6d3 commit 21d90ad

12 files changed

+53
-60
lines changed

Diff for: package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"email": "[email protected]"
2626
},
2727
"dependencies": {
28-
"@mongodb-js/saslprep": "^1.1.0",
28+
"@mongodb-js/saslprep": "^1.1.5",
2929
"bson": "^6.4.0",
3030
"mongodb-connection-string-url": "^3.0.0"
3131
},

Diff for: src/cmap/connect.ts

-5
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ export async function makeSocket(options: MakeConnectionOptions): Promise<Stream
319319
const useTLS = options.tls ?? false;
320320
const noDelay = options.noDelay ?? true;
321321
const connectTimeoutMS = options.connectTimeoutMS ?? 30000;
322-
const rejectUnauthorized = options.rejectUnauthorized ?? true;
323322
const existingSocket = options.existingSocket;
324323

325324
let socket: Stream;
@@ -375,10 +374,6 @@ export async function makeSocket(options: MakeConnectionOptions): Promise<Stream
375374
return socket;
376375
} catch (error) {
377376
socket.destroy();
378-
if ('authorizationError' in socket && socket.authorizationError != null && rejectUnauthorized) {
379-
// TODO(NODE-5192): wrap this with a MongoError subclass
380-
throw socket.authorizationError;
381-
}
382377
throw error;
383378
} finally {
384379
socket.setTimeout(0);

Diff for: src/mongo_logger.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ export function createStdioLogger(stream: {
220220
}): MongoDBLogWritable {
221221
return {
222222
write: promisify((log: Log, cb: (error?: Error) => void): unknown => {
223-
stream.write(inspect(log, { compact: true, breakLength: Infinity }), 'utf-8', cb);
223+
const logLine = inspect(log, { compact: true, breakLength: Infinity });
224+
stream.write(`${logLine}\n`, 'utf-8', cb);
224225
return;
225226
})
226227
};

Diff for: test/integration/auth/mongodb_aws.test.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,17 @@ describe('MONGODB-AWS', function () {
8888
});
8989

9090
describe('with missing aws token', () => {
91-
let awsSessionToken;
91+
let awsSessionToken: string | undefined;
9292

93-
beforeEach(function () {
93+
beforeEach(() => {
9494
awsSessionToken = process.env.AWS_SESSION_TOKEN;
9595
delete process.env.AWS_SESSION_TOKEN;
9696
});
9797

98-
afterEach(async () => {
99-
process.env.AWS_SESSION_TOKEN = awsSessionToken;
98+
afterEach(() => {
99+
if (awsSessionToken != null) {
100+
process.env.AWS_SESSION_TOKEN = awsSessionToken;
101+
}
100102
});
101103

102104
it('should not throw an exception when aws token is missing', async function () {

Diff for: test/integration/transactions-convenient-api/transactions-convenient-api.spec.test.ts

+2-13
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,8 @@ import { runUnifiedSuite } from '../../tools/unified-spec-runner/runner';
55

66
const SKIPPED_TESTS = [
77
'callback succeeds after multiple connection errors',
8-
'callback is not retried after non-transient error',
98
'callback is not retried after non-transient error (DuplicateKeyError)',
10-
'withTransaction succeeds if callback aborts',
11-
'unpin after transient error within a transaction',
12-
'withTransaction succeeds if callback commits',
13-
'withTransaction still succeeds if callback aborts and runs extra op',
14-
'withTransaction still succeeds if callback commits and runs extra op',
15-
'withTransaction commits after callback returns (second transaction)',
16-
'withTransaction commits after callback returns',
17-
'withTransaction and no transaction options set',
18-
'withTransaction inherits transaction options from defaultTransactionOptions',
19-
'withTransaction explicit transaction options override defaultTransactionOptions',
20-
'withTransaction explicit transaction options'
9+
'withTransaction succeeds if callback aborts'
2110
];
2211

2312
describe('Transactions Convenient API Spec Unified Tests', function () {
@@ -33,7 +22,7 @@ describe('Transactions Convenient API Spec Unified Tests', function () {
3322

3423
runUnifiedSuite(loadSpecTests(path.join('transactions-convenient-api', 'unified')), test => {
3524
return SKIPPED_TESTS.includes(test.description)
36-
? 'TODO(NODE-5855/DRIVERS-2816): Skipping failing transaction tests'
25+
? 'TODO(NODE-5855): Skipping failing transaction tests'
3726
: false;
3827
});
3928
});

Diff for: test/tools/unified-spec-runner/entities.ts

+6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ChangeStream,
88
ClientEncryption,
99
ClientSession,
10+
type ClusterTime,
1011
Collection,
1112
type CommandFailedEvent,
1213
type CommandStartedEvent,
@@ -556,6 +557,7 @@ export class EntitiesMap<E = Entity> extends Map<string, E> {
556557

557558
static async createEntities(
558559
config: TestConfiguration,
560+
clusterTime: ClusterTime | null,
559561
entities?: EntityDescription[],
560562
entityMap?: EntitiesMap
561563
): Promise<EntitiesMap> {
@@ -627,6 +629,10 @@ export class EntitiesMap<E = Entity> extends Map<string, E> {
627629
}
628630
}
629631
const session = client.startSession(options);
632+
// Advance the session cluster time. See DRIVERS-2816.
633+
if (clusterTime) {
634+
session.advanceClusterTime(clusterTime);
635+
}
630636
map.set(entity.session.id, session);
631637
} else if ('bucket' in entity) {
632638
const db = map.getEntity('db', entity.bucket.database);

Diff for: test/tools/unified-spec-runner/operations.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ operations.set('createEntities', async ({ entities, operation, testConfig }) =>
4545
if (!operation.arguments?.entities) {
4646
throw new Error('encountered createEntities operation without entities argument');
4747
}
48-
await EntitiesMap.createEntities(testConfig, operation.arguments.entities!, entities);
48+
await EntitiesMap.createEntities(testConfig, null, operation.arguments.entities!, entities);
4949
});
5050

5151
operations.set('abortTransaction', async ({ entities, operation }) => {

Diff for: test/tools/unified-spec-runner/runner.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,15 @@ async function runUnifiedTest(
160160
}
161161
}
162162

163+
const ping = await utilClient.db().admin().command({ ping: 1 });
164+
const clusterTime = ping.$clusterTime;
165+
163166
trace('createEntities');
164-
entities = await EntitiesMap.createEntities(ctx.configuration, unifiedSuite.createEntities);
167+
entities = await EntitiesMap.createEntities(
168+
ctx.configuration,
169+
clusterTime,
170+
unifiedSuite.createEntities
171+
);
165172

166173
// Workaround for SERVER-39704:
167174
// test runners MUST execute a non-transactional distinct command on

Diff for: test/unit/connection_string.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,8 @@ describe('Connection String', function () {
896896
});
897897
const log: Log = { t: new Date(), c: 'ConnectionStringStdErr', s: 'error' };
898898
client.options.mongoLoggerOptions.logDestination.write(log);
899-
expect(stderrStub.write).calledWith(inspect(log, { breakLength: Infinity, compact: true }));
899+
const logLine = inspect(log, { breakLength: Infinity, compact: true });
900+
expect(stderrStub.write).calledWith(`${logLine}\n`);
900901
});
901902
});
902903

@@ -907,7 +908,8 @@ describe('Connection String', function () {
907908
});
908909
const log: Log = { t: new Date(), c: 'ConnectionStringStdOut', s: 'error' };
909910
client.options.mongoLoggerOptions.logDestination.write(log);
910-
expect(stdoutStub.write).calledWith(inspect(log, { breakLength: Infinity, compact: true }));
911+
const logLine = inspect(log, { breakLength: Infinity, compact: true });
912+
expect(stdoutStub.write).calledWith(`${logLine}\n`);
911913
});
912914
});
913915

Diff for: test/unit/mongo_client.test.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -852,9 +852,8 @@ describe('MongoClient', function () {
852852
});
853853
const log = { t: new Date(), c: 'constructorStdErr', s: 'error' };
854854
client.options.mongoLoggerOptions.logDestination.write(log);
855-
expect(stderrStub.write).calledWith(
856-
inspect(log, { breakLength: Infinity, compact: true })
857-
);
855+
const logLine = inspect(log, { breakLength: Infinity, compact: true });
856+
expect(stderrStub.write).calledWith(`${logLine}\n`);
858857
});
859858
});
860859

@@ -882,9 +881,8 @@ describe('MongoClient', function () {
882881
});
883882
const log = { t: new Date(), c: 'constructorStdOut', s: 'error' };
884883
client.options.mongoLoggerOptions.logDestination.write(log);
885-
expect(stdoutStub.write).calledWith(
886-
inspect(log, { breakLength: Infinity, compact: true })
887-
);
884+
const logLine = inspect(log, { breakLength: Infinity, compact: true });
885+
expect(stdoutStub.write).calledWith(`${logLine}\n`);
888886
});
889887
});
890888

@@ -939,9 +937,8 @@ describe('MongoClient', function () {
939937
});
940938
const log = { t: new Date(), c: 'constructorStdErr', s: 'error' };
941939
client.options.mongoLoggerOptions.logDestination.write(log);
942-
expect(stderrStub.write).calledWith(
943-
inspect(log, { breakLength: Infinity, compact: true })
944-
);
940+
const logLine = inspect(log, { breakLength: Infinity, compact: true });
941+
expect(stderrStub.write).calledWith(`${logLine}\n`);
945942
});
946943
});
947944
});

Diff for: test/unit/mongo_logger.test.ts

+13-19
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,8 @@ describe('class MongoLogger', async function () {
443443
const log: Log = { t: new Date(), c: 'command', s: 'error' };
444444
options.logDestination.write(log);
445445

446-
expect(stderrStub.write).to.have.been.calledOnceWith(
447-
inspect(log, { breakLength: Infinity, compact: true })
448-
);
446+
const logLine = inspect(log, { breakLength: Infinity, compact: true });
447+
expect(stderrStub.write).to.have.been.calledOnceWith(`${logLine}\n`);
449448
});
450449
}
451450
}
@@ -465,9 +464,8 @@ describe('class MongoLogger', async function () {
465464
const log: Log = { t: new Date(), c: 'command', s: 'error' };
466465
options.logDestination.write(log);
467466

468-
expect(stderrStub.write).to.have.been.calledOnceWith(
469-
inspect(log, { breakLength: Infinity, compact: true })
470-
);
467+
const logLine = inspect(log, { breakLength: Infinity, compact: true });
468+
expect(stderrStub.write).to.have.been.calledOnceWith(`${logLine}\n`);
471469
});
472470
}
473471
}
@@ -512,9 +510,8 @@ describe('class MongoLogger', async function () {
512510
const log: Log = { t: new Date(), c: 'command', s: 'error' };
513511
options.logDestination.write(log);
514512

515-
expect(stderrStub.write).to.have.been.calledOnceWith(
516-
inspect(log, { breakLength: Infinity, compact: true })
517-
);
513+
const logLine = inspect(log, { breakLength: Infinity, compact: true });
514+
expect(stderrStub.write).to.have.been.calledOnceWith(`${logLine}\n`);
518515
});
519516
}
520517
}
@@ -536,9 +533,8 @@ describe('class MongoLogger', async function () {
536533
const log: Log = { t: new Date(), c: 'command', s: 'error' };
537534
options.logDestination.write(log);
538535

539-
expect(stderrStub.write).to.have.been.calledOnceWith(
540-
inspect(log, { breakLength: Infinity, compact: true })
541-
);
536+
const logLine = inspect(log, { breakLength: Infinity, compact: true });
537+
expect(stderrStub.write).to.have.been.calledOnceWith(`${logLine}\n`);
542538
});
543539
}
544540
}
@@ -1399,9 +1395,8 @@ describe('class MongoLogger', async function () {
13991395
logger.debug('client', 'random message');
14001396
let stderrStubCall = stderrStub.write.getCall(0).args[0];
14011397
stderrStubCall = stderrStubCall.slice(stderrStubCall.search('c:'));
1402-
expect(stderrStubCall).to.equal(
1403-
`c: 'client', s: 'error', message: 'User input for mongodbLogPath is now invalid. Logging is halted.', error: 'This writable always throws' }`
1404-
);
1398+
const expectedLogLine1 = `c: 'client', s: 'error', message: 'User input for mongodbLogPath is now invalid. Logging is halted.', error: 'This writable always throws' }`;
1399+
expect(stderrStubCall).to.equal(`${expectedLogLine1}\n`);
14051400

14061401
// logging is halted
14071402
logger.debug('client', 'random message 2');
@@ -1450,9 +1445,8 @@ describe('class MongoLogger', async function () {
14501445
// stderr now contains the error message
14511446
let stderrStubCall = stderrStub.write.getCall(0).args[0];
14521447
stderrStubCall = stderrStubCall.slice(stderrStubCall.search('c:'));
1453-
expect(stderrStubCall).to.equal(
1454-
`c: 'client', s: 'error', message: 'User input for mongodbLogPath is now invalid. Logging is halted.', error: 'This writable always throws, but only after at least 500ms' }`
1455-
);
1448+
const expectedLogLine1 = `c: 'client', s: 'error', message: 'User input for mongodbLogPath is now invalid. Logging is halted.', error: 'This writable always throws, but only after at least 500ms' }`;
1449+
expect(stderrStubCall).to.equal(`${expectedLogLine1}\n`);
14561450

14571451
// no more logging in the future
14581452
logger.debug('client', 'random message 2');
@@ -1480,7 +1474,7 @@ describe('class MongoLogger', async function () {
14801474
let stderrStubCall = stderrStub.write.getCall(0).args[0];
14811475
stderrStubCall = stderrStubCall.slice(stderrStubCall.search('c:'));
14821476
expect(stderrStubCall).to.equal(
1483-
`c: 'client', s: 'error', message: 'User input for mongodbLogPath is now invalid. Logging is halted.', error: 'I am stdout and do not work' }`
1477+
`c: 'client', s: 'error', message: 'User input for mongodbLogPath is now invalid. Logging is halted.', error: 'I am stdout and do not work' }\n`
14841478
);
14851479

14861480
// logging is halted

0 commit comments

Comments
 (0)