Skip to content

Commit da820bb

Browse files
committed
fix: more tests
1 parent dc132f4 commit da820bb

5 files changed

Lines changed: 30 additions & 14 deletions

File tree

test/integration/connection-monitoring-and-pooling/connection.test.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ import { skipBrokenAuthTestBeforeEachHook } from '../../tools/runner/hooks/confi
2525
import { sleep } from '../../tools/utils';
2626
import { assert as test, setupDatabase } from '../shared';
2727

28-
const commonConnectOptions = {
28+
const commonConnectOptions = client => ({
2929
id: 1,
3030
generation: 1,
3131
monitorCommands: false,
3232
tls: false,
3333
loadBalanced: false,
3434
// Will be overridden by configuration options
3535
hostAddress: HostAddress.fromString('127.0.0.1:1'),
36-
authProviders: new MongoClientAuthProviders()
37-
};
36+
authProviders: new MongoClientAuthProviders(client)
37+
});
3838

3939
describe('Connection', function () {
4040
beforeEach(
@@ -50,21 +50,31 @@ describe('Connection', function () {
5050
return setupDatabase(this.configuration);
5151
});
5252

53+
let client;
54+
55+
beforeEach(async function () {
56+
client = this.configuration.newClient();
57+
});
58+
59+
afterEach(async function () {
60+
await client.close();
61+
});
62+
5363
describe('Connection.command', function () {
5464
it('should execute a command against a server', {
5565
metadata: { requires: { apiVersion: false, topology: '!load-balanced' } },
5666
test: async function () {
5767
const connectOptions: ConnectionOptions = {
58-
...commonConnectOptions,
68+
...commonConnectOptions(client),
5969
connectionType: Connection,
6070
...this.configuration.options,
6171
metadata: makeClientMetadata({ driverInfo: {} }),
62-
extendedMetadata: addContainerMetadata(makeClientMetadata({ driverInfo: {} }))
72+
extendedMetadata: addContainerMetadata(client, makeClientMetadata({ driverInfo: {} }))
6373
};
6474

6575
let conn;
6676
try {
67-
conn = await connect(connectOptions);
77+
conn = await connect(client, connectOptions);
6878
const hello = await conn?.command(ns('admin.$cmd'), { [LEGACY_HELLO_COMMAND]: 1 });
6979
expect(hello).to.have.property('ok', 1);
7080
} finally {
@@ -77,17 +87,17 @@ describe('Connection', function () {
7787
metadata: { requires: { apiVersion: false, topology: '!load-balanced' } },
7888
test: async function () {
7989
const connectOptions: ConnectionOptions = {
80-
...commonConnectOptions,
90+
...commonConnectOptions(client),
8191
connectionType: Connection,
8292
...this.configuration.options,
8393
monitorCommands: true,
8494
metadata: makeClientMetadata({ driverInfo: {} }),
85-
extendedMetadata: addContainerMetadata(makeClientMetadata({ driverInfo: {} }))
95+
extendedMetadata: addContainerMetadata(client, makeClientMetadata({ driverInfo: {} }))
8696
};
8797

8898
let conn;
8999
try {
90-
conn = await connect(connectOptions);
100+
conn = await connect(client, connectOptions);
91101

92102
const events: any[] = [];
93103
conn.on('commandStarted', event => events.push(event));
@@ -109,17 +119,17 @@ describe('Connection', function () {
109119
metadata: { requires: { apiVersion: false, topology: '!load-balanced' } },
110120
test: async function () {
111121
const connectOptions: ConnectionOptions = {
112-
...commonConnectOptions,
122+
...commonConnectOptions(client),
113123
connectionType: Connection,
114124
...this.configuration.options,
115125
monitorCommands: true,
116126
metadata: makeClientMetadata({ driverInfo: {} }),
117-
extendedMetadata: addContainerMetadata(makeClientMetadata({ driverInfo: {} }))
127+
extendedMetadata: addContainerMetadata(client, makeClientMetadata({ driverInfo: {} }))
118128
};
119129

120130
let conn;
121131
try {
122-
conn = await connect(connectOptions);
132+
conn = await connect(client, connectOptions);
123133

124134
const toObjectSpy = sinon.spy(MongoDBResponse.prototype, 'toObject');
125135

test/integration/node-specific/client_close.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ describe('MongoClient.close() Integration', () => {
596596
await runScriptAndGetProcessInfo(
597597
'tls-file-read-auto-encryption',
598598
this.configuration,
599-
async function run({ MongoClient, uri, expect, mongodb }) {
599+
async function run({ MongoClient, uri, expect, mongodb, getCSFLEKMSProviders }) {
600600
const infiniteFile = '/dev/zero';
601601

602602
const kmsProviders = getCSFLEKMSProviders();

test/integration/node-specific/resource_tracking_script_builder.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export type ProcessResourceTestFunction = (options: {
3232
timers?: typeof timers;
3333
getSocketReport?: () => { host: string; port: string };
3434
getSocketEndpointReport?: () => any;
35+
getCSFLEKMSProviders: () => Record<string, any>;
3536
once?: () => typeof once;
3637
}) => Promise<void>;
3738

test/tools/cmap_spec_runner.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,10 @@ async function runCmapTest(test: CmapTest, threadContext: ThreadContext) {
377377
}
378378

379379
const metadata = makeClientMetadata({ appName: poolOptions.appName, driverInfo: {} });
380-
const extendedMetadata = addContainerMetadata(metadata);
380+
const extendedMetadata = addContainerMetadata(
381+
{ io: { fs: { readFile: async () => Buffer.alloc(0), access: async () => false } } },
382+
metadata
383+
);
381384
delete poolOptions.appName;
382385

383386
const operations = test.operations;

test/tools/fixtures/process_resource_script.in.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const { expect } = require('chai');
1616
const timers = require('node:timers');
1717
const { setTimeout } = timers;
1818
const { once } = require('node:events');
19+
const { getCSFLEKMSProviders } = require('../../csfle-kms-providers');
1920

2021
let originalReport;
2122
const logFile = scriptName + '.logs.txt';
@@ -121,6 +122,7 @@ async function main() {
121122
getTimerCount,
122123
getSockets,
123124
getSocketEndpoints,
125+
getCSFLEKMSProviders,
124126
once
125127
});
126128
log({ newResources: getNewResources() });

0 commit comments

Comments
 (0)