-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathconnection_pool.test.ts
66 lines (58 loc) · 2.21 KB
/
connection_pool.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { once } from 'node:events';
import { expect } from 'chai';
import { type ConnectionPoolCreatedEvent, type Db, type MongoClient } from '../../mongodb';
describe('Connection Pool', function () {
let client: MongoClient;
let db: Db;
afterEach(async function () {
if (client) {
if (db) {
await db.dropDatabase();
}
await client.close();
}
});
describe('Events', function () {
describe('ConnectionPoolCreatedEvent', function () {
context('when no connection pool options are passed in', function () {
let pConnectionPoolCreated: Promise<ConnectionPoolCreatedEvent[]>;
let connectionPoolCreated: ConnectionPoolCreatedEvent;
beforeEach(async function () {
client = this.configuration.newClient({}, {});
pConnectionPoolCreated = once(client, 'connectionPoolCreated');
await client.connect();
connectionPoolCreated = (await pConnectionPoolCreated)[0];
});
it('the options field matches the default options', function () {
expect(connectionPoolCreated).to.have.deep.property('options', {
waitQueueTimeoutMS: 0,
maxIdleTimeMS: 0,
maxConnecting: 2,
minPoolSize: 0,
maxPoolSize: 100
});
});
});
context('when valid non-default connection pool options are passed in', function () {
let pConnectionPoolCreated: Promise<ConnectionPoolCreatedEvent[]>;
let connectionPoolCreated: ConnectionPoolCreatedEvent;
const options = {
waitQueueTimeoutMS: 2000,
maxIdleTimeMS: 1,
maxConnecting: 3,
minPoolSize: 1,
maxPoolSize: 101
};
beforeEach(async function () {
client = this.configuration.newClient({}, options);
pConnectionPoolCreated = once(client, 'connectionPoolCreated');
await client.connect();
connectionPoolCreated = (await pConnectionPoolCreated)[0];
});
it('the options field only contains keys and values matching the non-default options', function () {
expect(connectionPoolCreated).to.have.deep.property('options', options);
});
});
});
});
});