-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sessions): transfer control of session management to session pool
Part of HELP-5834
- Loading branch information
1 parent
46e14d1
commit 6dde985
Showing
10 changed files
with
95 additions
and
54 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
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
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
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
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,51 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const sinon = require('sinon'); | ||
const core = require('mongodb-core'); | ||
const Server = core.Server; | ||
const ReplSet = core.ReplSet; | ||
const Mongos = core.Mongos; | ||
const ServerSessionPool = core.Sessions.ServerSessionPool; | ||
|
||
(() => { | ||
const sandbox = sinon.createSandbox(); | ||
|
||
beforeEach('Session Leak Before Each - setup session tracking', function() { | ||
sandbox.spy(Server.prototype, 'endSessions'); | ||
sandbox.spy(ReplSet.prototype, 'endSessions'); | ||
sandbox.spy(Mongos.prototype, 'endSessions'); | ||
sandbox.spy(ServerSessionPool.prototype, 'acquire'); | ||
}); | ||
|
||
afterEach('Session Leak After Each - ensure no leaks', function() { | ||
const poolCalls = ServerSessionPool.prototype.acquire.getCalls(); | ||
const endCalls = Server.prototype.endSessions | ||
.getCalls() | ||
.concat(ReplSet.prototype.endSessions.getCalls()) | ||
.concat(Mongos.prototype.endSessions.getCalls()); | ||
|
||
const sessions = new Set(); | ||
poolCalls.forEach(call => sessions.add(call.returnValue.id)); | ||
// const totalSessionCount = set.size; | ||
|
||
endCalls.forEach(call => { | ||
const arg = call.args[0]; | ||
const ids = Array.isArray(arg) ? arg : [arg]; | ||
|
||
ids.forEach(id => sessions.delete(id)); | ||
}); | ||
|
||
const leakedSessionCount = sessions.size; | ||
try { | ||
expect( | ||
leakedSessionCount, | ||
`test is leaking ${leakedSessionCount} sessions, when it should be leaking 0` | ||
).to.equal(0); | ||
} catch (e) { | ||
this.test.error(e); | ||
} | ||
}); | ||
|
||
afterEach('Session Leak After Each - restore sandbox', () => sandbox.restore()); | ||
})(); |