Skip to content

Commit 4add48c

Browse files
committed
metadata filter not working?
1 parent ff8e814 commit 4add48c

File tree

2 files changed

+88
-73
lines changed

2 files changed

+88
-73
lines changed

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

Lines changed: 76 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -66,81 +66,88 @@ describe('Connection Pool', function () {
6666
});
6767
});
6868

69-
describe(
70-
'ConnectionCheckedInEvent',
71-
{ requires: { mongodb: '>=4.4', topology: 'single' } },
72-
function () {
73-
let client: MongoClient;
69+
const metadata: MongoDBMetadataUI = { requires: { mongodb: '>=4.4', topology: 'single' } };
70+
71+
describe('ConnectionCheckedInEvent', metadata, function () {
72+
let client: MongoClient;
73+
74+
beforeEach(async function () {
75+
if (!this.configuration.filters.MongoDBVersionFilter.filter({ metadata })) {
76+
return;
77+
}
78+
if (!this.configuration.filters.MongoDBTopologyFilter.filter({ metadata })) {
79+
return;
80+
}
81+
82+
await configureFailPoint(this.configuration, {
83+
configureFailPoint: 'failCommand',
84+
mode: 'alwaysOn',
85+
data: {
86+
failCommands: ['insert'],
87+
blockConnection: true,
88+
blockTimeMS: 500
89+
}
90+
});
7491

75-
beforeEach(async function () {
76-
await configureFailPoint(this.configuration, {
77-
configureFailPoint: 'failCommand',
78-
mode: 'alwaysOn',
79-
data: {
80-
failCommands: ['insert'],
81-
blockConnection: true,
82-
blockTimeMS: 500
92+
client = this.configuration.newClient();
93+
await client.connect();
94+
await Promise.all(Array.from({ length: 100 }, () => client.db().command({ ping: 1 })));
95+
});
96+
97+
afterEach(async function () {
98+
if (this.configuration.filters.MongoDBVersionFilter.filter({ metadata })) {
99+
await clearFailPoint(this.configuration);
100+
}
101+
await client.close();
102+
});
103+
104+
describe('when a MongoClient is closed', function () {
105+
it(
106+
'a connection pool emits checked in events for closed connections',
107+
metadata,
108+
async () => {
109+
const allClientEvents = [];
110+
const pushToClientEvents = e => allClientEvents.push(e);
111+
112+
client
113+
.on('connectionCheckedOut', pushToClientEvents)
114+
.on('connectionCheckedIn', pushToClientEvents)
115+
.on('connectionClosed', pushToClientEvents);
116+
117+
const inserts = Promise.allSettled([
118+
client.db('test').collection('test').insertOne({ a: 1 }),
119+
client.db('test').collection('test').insertOne({ a: 1 }),
120+
client.db('test').collection('test').insertOne({ a: 1 })
121+
]);
122+
123+
// wait until all pings are pending on the server
124+
while (allClientEvents.filter(e => e.name === 'connectionCheckedOut').length < 3) {
125+
await sleep(1);
83126
}
84-
});
85127

86-
client = this.configuration.newClient();
87-
await client.connect();
88-
await Promise.all(Array.from({ length: 100 }, () => client.db().command({ ping: 1 })));
89-
});
128+
const insertConnectionIds = allClientEvents
129+
.filter(e => e.name === 'connectionCheckedOut')
130+
.map(({ address, connectionId }) => `${address} + ${connectionId}`);
90131

91-
afterEach(async function () {
92-
await clearFailPoint(this.configuration);
93-
await client.close();
94-
});
132+
await client.close();
95133

96-
describe('when a MongoClient is closed', function () {
97-
it(
98-
'a connection pool emits checked in events for closed connections',
99-
{ requires: { mongodb: '>=4.4', topology: 'single' } },
100-
async () => {
101-
const allClientEvents = [];
102-
const pushToClientEvents = e => allClientEvents.push(e);
103-
104-
client
105-
.on('connectionCheckedOut', pushToClientEvents)
106-
.on('connectionCheckedIn', pushToClientEvents)
107-
.on('connectionClosed', pushToClientEvents);
108-
109-
const inserts = Promise.allSettled([
110-
client.db('test').collection('test').insertOne({ a: 1 }),
111-
client.db('test').collection('test').insertOne({ a: 1 }),
112-
client.db('test').collection('test').insertOne({ a: 1 })
113-
]);
114-
115-
// wait until all pings are pending on the server
116-
while (allClientEvents.filter(e => e.name === 'connectionCheckedOut').length < 3) {
117-
await sleep(1);
118-
}
119-
120-
const insertConnectionIds = allClientEvents
121-
.filter(e => e.name === 'connectionCheckedOut')
122-
.map(({ address, connectionId }) => `${address} + ${connectionId}`);
123-
124-
await client.close();
125-
126-
const insertCheckInAndCloses = allClientEvents
127-
.filter(e => e.name === 'connectionCheckedIn' || e.name === 'connectionClosed')
128-
.filter(({ address, connectionId }) =>
129-
insertConnectionIds.includes(`${address} + ${connectionId}`)
130-
);
131-
132-
expect(insertCheckInAndCloses).to.have.lengthOf(6);
133-
134-
// check that each check-in is followed by a close (not proceeded by one)
135-
expect(insertCheckInAndCloses.map(e => e.name)).to.deep.equal(
136-
Array.from({ length: 3 }, () => ['connectionCheckedIn', 'connectionClosed']).flat(1)
134+
const insertCheckInAndCloses = allClientEvents
135+
.filter(e => e.name === 'connectionCheckedIn' || e.name === 'connectionClosed')
136+
.filter(({ address, connectionId }) =>
137+
insertConnectionIds.includes(`${address} + ${connectionId}`)
137138
);
138139

139-
await inserts;
140-
}
141-
);
142-
});
143-
}
144-
);
140+
expect(insertCheckInAndCloses).to.have.lengthOf(6);
141+
142+
// check that each check-in is followed by a close (not proceeded by one)
143+
expect(insertCheckInAndCloses.map(e => e.name)).to.deep.equal(
144+
Array.from({ length: 3 }, () => ['connectionCheckedIn', 'connectionClosed']).flat(1)
145+
);
146+
147+
await inserts;
148+
}
149+
);
150+
});
151+
});
145152
});
146153
});

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,13 +1066,22 @@ describe('class MongoClient', function () {
10661066
});
10671067
});
10681068

1069+
const metadata: MongoDBMetadataUI = { requires: { mongodb: '>=4.4', topology: 'single' } };
1070+
10691071
describe(
10701072
'maxPoolSize is not fully used when running clean up operations',
1071-
{ requires: { mongodb: '>=4.4', topology: 'single' } },
1073+
metadata,
10721074
function () {
10731075
let client;
10741076

10751077
beforeEach(async function () {
1078+
if (!this.configuration.filters.MongoDBVersionFilter.filter({ metadata })) {
1079+
return;
1080+
}
1081+
if (!this.configuration.filters.MongoDBTopologyFilter.filter({ metadata })) {
1082+
return;
1083+
}
1084+
10761085
await configureFailPoint(this.configuration, {
10771086
configureFailPoint: 'failCommand',
10781087
mode: 'alwaysOn',
@@ -1093,7 +1102,7 @@ describe('class MongoClient', function () {
10931102

10941103
it(
10951104
'closes in-use connections before running clean up operations avoiding a deadlock',
1096-
{ requires: { mongodb: '>=4.4', topology: 'single' } },
1105+
metadata,
10971106
async () => {
10981107
const inserted = client
10991108
.db('t')
@@ -1105,11 +1114,10 @@ describe('class MongoClient', function () {
11051114

11061115
const start = performance.now();
11071116
await client.close();
1108-
const error = await inserted;
1117+
await inserted;
11091118
const end = performance.now();
11101119

11111120
expect(end - start).to.be.lessThan(100);
1112-
expect(error).to.be.instanceOf(MongoClientClosedError);
11131121
}
11141122
);
11151123
}

0 commit comments

Comments
 (0)