Skip to content

Commit ff733b3

Browse files
committed
test: add tests around pool reset behavior
1 parent 920cf27 commit ff733b3

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

lib/core/connection/pool.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,10 @@ function destroy(self, connections, options, callback) {
643643
*/
644644
Pool.prototype.destroy = function(force, callback) {
645645
var self = this;
646+
if (typeof force === 'function') {
647+
callback = force;
648+
force = false;
649+
}
646650

647651
// Do not try again if the pool is already dead
648652
if (this.state === DESTROYED || self.state === DESTROYING) {

test/core/functional/pool_tests.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,4 +1160,45 @@ describe('Pool tests', function() {
11601160
});
11611161
}
11621162
});
1163+
1164+
it('should support resetting', function(done) {
1165+
const pool = new Pool(null, {
1166+
host: this.configuration.host,
1167+
port: this.configuration.port,
1168+
bson: new Bson()
1169+
});
1170+
1171+
const isMasterQuery = new Query(
1172+
new Bson(),
1173+
'system.$cmd',
1174+
{ ismaster: true },
1175+
{ numberToSkip: 0, numberToReturn: 1 }
1176+
);
1177+
1178+
pool.once('connect', () => {
1179+
const connections = pool.allConnections().map(conn => conn.id);
1180+
expect(connections).to.have.length(1);
1181+
1182+
pool.write(isMasterQuery, err => {
1183+
expect(err).to.not.exist;
1184+
1185+
pool.reset(err => {
1186+
expect(err).to.not.exist;
1187+
1188+
pool.write(isMasterQuery, err => {
1189+
expect(err).to.not.exist;
1190+
1191+
// verify the previous connection was dropped, and a new connection was created
1192+
const newConnections = pool.allConnections().map(conn => conn.id);
1193+
expect(newConnections).to.have.length(1);
1194+
expect(newConnections[0]).to.not.equal(connections[0]);
1195+
1196+
pool.destroy(done);
1197+
});
1198+
});
1199+
});
1200+
});
1201+
1202+
pool.connect();
1203+
});
11631204
});

0 commit comments

Comments
 (0)