Skip to content

Commit 6fe6954

Browse files
committed
move client creation into tests
1 parent c0999ca commit 6fe6954

1 file changed

Lines changed: 9 additions & 18 deletions

File tree

test/integration/client-backpressure/client-backpressure.prose.test.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { expect } from 'chai';
22
import * as sinon from 'sinon';
33

44
import {
5-
type Collection,
65
INITIAL_TOKEN_BUCKET_SIZE,
76
MAX_RETRIES,
87
type MongoClient,
@@ -13,18 +12,11 @@ import { filterForCommands } from '../shared';
1312

1413
describe('Client Backpressure (Prose)', function () {
1514
let client: MongoClient;
16-
let collection: Collection;
17-
18-
beforeEach(async function () {
19-
client = this.configuration.newClient();
20-
await client.connect();
21-
22-
collection = client.db('foo').collection('bar');
23-
});
2415

2516
afterEach(async function () {
2617
sinon.restore();
2718
await client.close();
19+
client = undefined;
2820
await clearFailPoint(this.configuration);
2921
});
3022

@@ -36,6 +28,9 @@ describe('Client Backpressure (Prose)', function () {
3628
}
3729
},
3830
async function () {
31+
client = this.configuration.newClient();
32+
await client.connect();
33+
3934
await configureFailPoint(this.configuration, {
4035
configureFailPoint: 'failCommand',
4136
mode: 'alwaysOn',
@@ -50,6 +45,8 @@ describe('Client Backpressure (Prose)', function () {
5045

5146
stub.returns(0);
5247

48+
const collection = client.db('foo').collection('bar');
49+
5350
const { duration: durationNoBackoff } = await measureDuration(async () => {
5451
const error = await collection.insertOne({ a: 1 }).catch(e => e);
5552
expect(error).to.be.instanceof(MongoServerError);
@@ -68,7 +65,7 @@ describe('Client Backpressure (Prose)', function () {
6865

6966
it('Test 2: Token Bucket capacity is Enforced', async function () {
7067
// 1. Let client be a MongoClient with adaptiveRetries=True.
71-
const client = this.configuration.newClient({
68+
client = this.configuration.newClient({
7269
adaptiveRetries: true
7370
});
7471
await client.connect();
@@ -83,8 +80,6 @@ describe('Client Backpressure (Prose)', function () {
8380

8481
// 4. Assert that the successful command did not increase the number of tokens in the bucket above DEFAULT_RETRY_TOKEN_CAPACITY.
8582
expect(tokenBucket).to.have.property('budget').that.is.at.most(INITIAL_TOKEN_BUCKET_SIZE);
86-
87-
await client.close();
8883
});
8984

9085
it(
@@ -96,7 +91,7 @@ describe('Client Backpressure (Prose)', function () {
9691
},
9792
async function () {
9893
// 1. Let `client` be a `MongoClient` with command event monitoring enabled.
99-
const client = this.configuration.newClient({
94+
client = this.configuration.newClient({
10095
monitorCommands: true
10196
});
10297
await client.connect();
@@ -138,8 +133,6 @@ describe('Client Backpressure (Prose)', function () {
138133

139134
// 6. Assert that the total number of started commands is MAX_RETRIES + 1 (6).
140135
expect(commandsStarted).to.have.length(MAX_RETRIES + 1);
141-
142-
await client.close();
143136
}
144137
);
145138

@@ -152,7 +145,7 @@ describe('Client Backpressure (Prose)', function () {
152145
},
153146
async function () {
154147
// 1. Let `client` be a `MongoClient` with `adaptiveRetries=True` and command event monitoring enabled.
155-
const client = this.configuration.newClient({
148+
client = this.configuration.newClient({
156149
adaptiveRetries: true,
157150
monitorCommands: true
158151
});
@@ -199,8 +192,6 @@ describe('Client Backpressure (Prose)', function () {
199192

200193
// 7. Assert that the total number of started commands is 3: one for the initial attempt and two for the retries.
201194
expect(commandsStarted).to.have.length(3);
202-
203-
await client.close();
204195
}
205196
);
206197
});

0 commit comments

Comments
 (0)