This repository has been archived by the owner on Feb 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(mongos): remove listener on destroy event
NODE-1216 #257
- Loading branch information
Jessica Lord
authored
Dec 13, 2017
1 parent
de0105c
commit 243e942
Showing
2 changed files
with
62 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const Mongos = require('../../../../lib/topologies/mongos'); | ||
const mock = require('../../../mock'); | ||
const MongosFixture = require('../common').MongosFixture; | ||
|
||
const test = new MongosFixture(); | ||
|
||
describe('EventEmitters (Mongos)', function() { | ||
afterEach(() => mock.cleanup()); | ||
beforeEach(() => { | ||
return mock.createServer().then(mockServer => { | ||
test.server = mockServer; | ||
}); | ||
}); | ||
|
||
it('should remove `serverDescriptionChanged` listeners when server is closed', { | ||
metadata: { requires: { topology: ['single'] } }, | ||
test: function(done) { | ||
test.server.setMessageHandler(req => { | ||
const doc = req.document; | ||
if (doc.ismaster) { | ||
req.reply(Object.assign({}, test.defaultFields)); | ||
} | ||
}); | ||
|
||
const mongos = new Mongos([test.server.address()], { | ||
connectionTimeout: 30000, | ||
socketTimeout: 30000, | ||
haInterval: 500, | ||
size: 1 | ||
}); | ||
|
||
mongos.on('error', done); | ||
mongos.once('connect', () => { | ||
expect(mongos.disconnectedProxies).to.have.length(1); | ||
expect(mongos.disconnectedProxies[0].listenerCount('serverDescriptionChanged')).to.equal(1); | ||
// After we connect, destroy/close the server | ||
mongos.destroy(); | ||
mongos.on('topologyClosed', () => { | ||
expect(mongos.disconnectedProxies).to.have.length(1); | ||
expect(mongos.disconnectedProxies[0].listenerCount('serverDescriptionChanged')).to.equal( | ||
0 | ||
); | ||
}); | ||
|
||
done(); | ||
}); | ||
|
||
mongos.connect(); | ||
} | ||
}); | ||
}); |