Skip to content

Commit

Permalink
fix(connection): bubble up connected/disconnected events with unified…
Browse files Browse the repository at this point in the history
… topology
  • Loading branch information
vkarpov15 committed Nov 13, 2019
1 parent 98facde commit 4ec852d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/connection.js
Expand Up @@ -643,6 +643,12 @@ Connection.prototype.openUri = function(uri, options, callback) {
if (options.useUnifiedTopology) {
if (type === 'Single') {
const server = Array.from(db.s.topology.s.servers.values())[0];
server.s.pool.on('close', () => {
_this.readyState = STATES.disconnected;
});
server.s.topology.on('serverHeartbeatSucceeded', () => {
_handleReconnect();
});
server.s.pool.on('reconnect', () => {
_handleReconnect();
});
Expand Down
2 changes: 1 addition & 1 deletion test/connection.test.js
Expand Up @@ -189,7 +189,7 @@ describe('connections:', function() {
let numReconnected = 0;
let numReconnect = 0;
let numClose = 0;
const conn = mongoose.createConnection('mongodb://localhost:27000/mongoosetest', {
const conn = mongoose.createConnection('mongodb://localhost:27000/mongoosetest?heartbeatfrequencyms=1000', {
useNewUrlParser: true,
useUnifiedTopology: true
});
Expand Down

0 comments on commit 4ec852d

Please sign in to comment.