Skip to content

Commit ffcc8d5

Browse files
committed
fix: pr feedback
1 parent 516686b commit ffcc8d5

File tree

3 files changed

+31
-34
lines changed

3 files changed

+31
-34
lines changed

test/unit/cmap/connect.test.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { type ConnectionOptions } from 'node:tls';
21

32
import { type Document } from 'bson';
43
import { expect } from 'chai';
54

65
import { MongoCredentials } from '../../../src/cmap/auth/mongo_credentials';
76
import { connect, prepareHandshakeDocument } from '../../../src/cmap/connect';
8-
import { type Connection } from '../../../src/cmap/connection';
7+
import { ConnectionOptions, type Connection } from '../../../src/cmap/connection';
98
import {
109
addContainerMetadata,
1110
type ClientMetadata
@@ -181,15 +180,13 @@ describe('Connect Tests', function () {
181180
});
182181

183182
it('should emit `MongoNetworkError` for network errors', async function () {
184-
try {
185-
await connect({
186-
hostAddress: new HostAddress('non-existent:27018')
187-
});
188-
} catch (error) {
189-
expect(error).to.be.instanceOf(MongoNetworkError);
190-
}
183+
const error = await connect({
184+
hostAddress: new HostAddress('non-existent:27018')
185+
}).catch(e => e);
186+
expect(error).to.be.instanceOf(MongoNetworkError);
191187
});
192188

189+
193190
describe('prepareHandshakeDocument', () => {
194191
describe('client environment (containers and FAAS)', () => {
195192
const cachedEnv = process.env;

test/unit/collection.test.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ describe('Collection', function () {
5454
}
5555
];
5656
await collection.aggregate(pipeline, options).next();
57+
await client.close();
5758
}
5859

5960
context('bypass document validation', () => {
@@ -80,12 +81,12 @@ describe('Collection', function () {
8081
});
8182
}
8283

83-
if (isHello(doc)) {
84-
request.reply(Object.assign({}, HELLO));
85-
} else if (doc.endSessions) {
86-
request.reply({ ok: 1 });
87-
}
88-
});
84+
if (isHello(doc)) {
85+
request.reply(Object.assign({}, HELLO));
86+
} else if (doc.endSessions) {
87+
request.reply({ ok: 1 });
88+
}
89+
});
8990

9091
await client.connect();
9192
const db = client.db('test');
@@ -94,6 +95,7 @@ describe('Collection', function () {
9495
const options = { bypassDocumentValidation: config.actual };
9596

9697
await collection.findOneAndUpdate({ name: 'Andy' }, { $inc: { score: 1 } }, options);
98+
await client.close();
9799
}
98100

99101
it('should only set bypass document validation if strictly true in findOneAndUpdate', async function () {
@@ -118,12 +120,12 @@ describe('Collection', function () {
118120
});
119121
}
120122

121-
if (isHello(doc)) {
122-
request.reply(Object.assign({}, HELLO));
123-
} else if (doc.endSessions) {
124-
request.reply({ ok: 1 });
125-
}
126-
});
123+
if (isHello(doc)) {
124+
request.reply(Object.assign({}, HELLO));
125+
} else if (doc.endSessions) {
126+
request.reply({ ok: 1 });
127+
}
128+
});
127129

128130
await client.connect();
129131
const db = client.db('test');
@@ -135,6 +137,7 @@ describe('Collection', function () {
135137
};
136138

137139
await collection.bulkWrite([{ insertOne: { document: { a: 1 } } }], options);
140+
await client.close();
138141
}
139142

140143
// ordered bulk write, testing change in ordered.js

test/unit/sdam/topology.test.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,16 @@ describe('Topology (unit)', function () {
115115
serverSelectionTimeoutMS: 0,
116116
socketTimeoutMS: 250
117117
});
118-
const server = await topology.selectServer('primary', {
119-
timeoutContext: ctx,
120-
operationName: 'none'
121-
});
122-
try {
123-
await server.command(new RunCursorCommandOperation(ns('admin.$cmd'), { ping: 1 }, {}), ctx);
124-
expect.fail('expected command to fail');
125-
} catch (err) {
126-
expect(err).to.exist;
127-
expect(err).to.match(/timed out/);
128-
} finally {
129-
topology.close();
130-
}
118+
const server = await topology
119+
.selectServer('primary', {
120+
timeoutContext: ctx, operationName: 'none'
121+
});
122+
const err = await server
123+
.command(new RunCursorCommandOperation(ns('admin.$cmd'), { ping: 1 }, {}), ctx)
124+
.catch(e => e);
125+
expect(err).to.exist;
126+
expect(err).to.match(/timed out/);
127+
topology.close();
131128
});
132129
});
133130

0 commit comments

Comments
 (0)