Skip to content

Commit 47c20db

Browse files
fix message formatting + test cases naming
1 parent 1aeb046 commit 47c20db

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

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

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,36 @@ describe.skip('MongoClient.close() Integration', () => {
4141

4242
describe('MongoClientAuthProviders', () => {
4343
describe('Node.js resource: Token file read', () => {
44+
let tokenFileEnvCache;
45+
46+
beforeEach(function () {
47+
if (process.env.AUTH === 'auth') {
48+
this.currentTest.skipReason = 'OIDC test environment requires auth disabled';
49+
return this.skip();
50+
}
51+
tokenFileEnvCache = process.env.OIDC_TOKEN_FILE;
52+
});
53+
54+
afterEach(function () {
55+
process.env.OIDC_TOKEN_FILE = tokenFileEnvCache;
56+
});
57+
4458
describe('when MongoClientAuthProviders is instantiated and token file read hangs', () => {
4559
it('the file read is interrupted by client.close()', async () => {
4660
await runScriptAndGetProcessInfo(
4761
'token-file-read',
4862
config,
49-
async function run({ MongoClient, uri, log, chai }) {
63+
async function run({ MongoClient, uri, chai }) {
5064
const infiniteFile = '/dev/zero';
51-
log({ ActiveResources: process.getActiveResourcesInfo() });
52-
53-
// speculative authentication call to getToken() is during initial handshake
54-
const client = new MongoClient(uri, {
55-
authMechanismProperties: { TOKEN_RESOURCE: infiniteFile }
56-
});
65+
process.env.OIDC_TOKEN_FILE = infiniteFile;
66+
const options = {
67+
authMechanismProperties: { ENVIRONMENT: 'test' },
68+
authMechanism: 'MONGODB-OIDC'
69+
};
70+
const client = new MongoClient(uri, options);
5771
client.connect();
58-
59-
log({ ActiveResources: process.getActiveResourcesInfo() });
60-
6172
chai.expect(process.getActiveResourcesInfo()).to.include('FSReqPromise');
6273
await client.close();
63-
6474
chai.expect(process.getActiveResourcesInfo()).to.not.include('FSReqPromise');
6575
}
6676
);
@@ -220,7 +230,7 @@ describe.skip('MongoClient.close() Integration', () => {
220230
describe('when KMSRequest reads an infinite TLS file', () => {
221231
it('the file read is interrupted by client.close()', async () => {
222232
await runScriptAndGetProcessInfo(
223-
'tls-file-read',
233+
'tls-file-read-auto-encryption',
224234
config,
225235
async function run({ MongoClient, uri, log, chai, ClientEncryption, BSON }) {
226236
const infiniteFile = '/dev/zero';
@@ -292,7 +302,7 @@ describe.skip('MongoClient.close() Integration', () => {
292302
await keyVaultClient.close();
293303
await encryptedClient.close();
294304

295-
chai.expect(process.getActiveResourcesInfo()).to.include('FSReqPromise');
305+
chai.expect(process.getActiveResourcesInfo()).to.not.include('FSReqPromise');
296306
log({ activeResourcesAfterClose: process.getActiveResourcesInfo() });
297307

298308
const err = await insertPromise.catch(e => e);
@@ -316,7 +326,7 @@ describe.skip('MongoClient.close() Integration', () => {
316326
describe('when KMSRequest reads an infinite TLS file read', () => {
317327
it('the file read is interrupted by client.close()', async () => {
318328
await runScriptAndGetProcessInfo(
319-
'tls-file-read',
329+
'tls-file-read-client-encryption',
320330
config,
321331
async function run({ MongoClient, uri, log, chai, ClientEncryption, BSON }) {
322332
const infiniteFile = '/dev/zero';
@@ -345,7 +355,7 @@ describe.skip('MongoClient.close() Integration', () => {
345355

346356
await keyVaultClient.close();
347357

348-
chai.expect(process.getActiveResourcesInfo()).to.include('FSReqPromise');
358+
chai.expect(process.getActiveResourcesInfo()).to.not.include('FSReqPromise');
349359

350360
log({ activeResourcesAfterClose: process.getActiveResourcesInfo() });
351361

test/integration/node-specific/resource_tracking_script_builder.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { fork, spawn } from 'node:child_process';
22
import { on, once } from 'node:events';
3-
import * as fs from 'node:fs';
43
import { readFile, unlink, writeFile } from 'node:fs/promises';
54
import * as path from 'node:path';
65

@@ -185,7 +184,11 @@ export async function runScriptAndGetProcessInfo(
185184
const [exitCode] = await willClose;
186185

187186
// format messages from child process as an object
188-
const messages = (await readFile(logFile, 'utf-8')).trim().split('\n').map(line => JSON.parse(line)).reduce((acc, curr) => ({ ...acc, ...curr }), {});
187+
const messages = (await readFile(logFile, 'utf-8'))
188+
.trim()
189+
.split('\n')
190+
.map(line => JSON.parse(line))
191+
.reduce((acc, curr) => ({ ...acc, ...curr }), {});
189192

190193
// delete temporary files
191194
await unlink(scriptName);

0 commit comments

Comments
 (0)