-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(NODE-6626): implement integration tests for improved client.close() - server-side #4367
base: NODE-6620/sockets
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
/* eslint-disable @typescript-eslint/no-empty-function */ | ||
import { expect } from 'chai'; | ||
|
||
import { type TestConfiguration } from '../../tools/runner/config'; | ||
import { runScriptAndGetProcessInfo } from './resource_tracking_script_builder'; | ||
|
||
|
@@ -500,29 +502,85 @@ describe.skip('MongoClient.close() Integration', () => { | |
}); | ||
|
||
describe('ClientSession (Implicit)', () => { | ||
let idleSessionsBeforeClose; | ||
let idleSessionsAfterClose; | ||
|
||
beforeEach(async function () { | ||
const client = this.configuration.newClient(); | ||
await client.connect(); | ||
const session = client.startSession({ explicit: false }); | ||
session.startTransaction(); | ||
await client.db('db').collection('collection').insertOne({ x: 1 }, { session }); | ||
|
||
const opBefore = await client.db().admin().command({ currentOp: 1 }); | ||
idleSessionsBeforeClose = opBefore.inprog.filter(s => s.type === 'idleSession'); | ||
|
||
await client.close(); | ||
await client.connect(); | ||
|
||
const opAfter = await client.db().admin().command({ currentOp: 1 }); | ||
idleSessionsAfterClose = opAfter.inprog.filter(s => s.type === 'idleSession'); | ||
|
||
await client.close(); | ||
}); | ||
|
||
describe('Server resource: LSID/ServerSession', () => { | ||
describe('after a clientSession is implicitly created and used', () => { | ||
it.skip('the server-side ServerSession is cleaned up by client.close()', async function () {}); | ||
it('the server-side ServerSession is cleaned up by client.close()', async function () { | ||
expect(idleSessionsBeforeClose).to.not.be.empty; | ||
expect(idleSessionsAfterClose).to.be.empty; | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Server resource: Transactions', () => { | ||
describe('after a clientSession is implicitly created and used', () => { | ||
it.skip('the server-side transaction is cleaned up by client.close()', async function () {}); | ||
it('the server-side transaction is cleaned up by client.close()', async function () { | ||
expect(idleSessionsBeforeClose[0].transaction.txnNumber).to.not.null; | ||
expect(idleSessionsAfterClose).to.be.empty; | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('ClientSession (Explicit)', () => { | ||
let idleSessionsBeforeClose; | ||
let idleSessionsAfterClose; | ||
|
||
beforeEach(async function () { | ||
const client = this.configuration.newClient(); | ||
await client.connect(); | ||
const session = client.startSession(); | ||
session.startTransaction(); | ||
await client.db('db').collection('collection').insertOne({ x: 1 }, { session }); | ||
|
||
const opBefore = await client.db().admin().command({ currentOp: 1 }); | ||
idleSessionsBeforeClose = opBefore.inprog.filter(s => s.type === 'idleSession'); | ||
|
||
await client.close(); | ||
await client.connect(); | ||
|
||
const opAfter = await client.db().admin().command({ currentOp: 1 }); | ||
idleSessionsAfterClose = opAfter.inprog.filter(s => s.type === 'idleSession'); | ||
|
||
await client.close(); | ||
}); | ||
|
||
describe('Server resource: LSID/ServerSession', () => { | ||
describe('after a clientSession is created and used', () => { | ||
it.skip('the server-side ServerSession is cleaned up by client.close()', async function () {}); | ||
it('the server-side ServerSession is cleaned up by client.close()', async function () { | ||
expect(idleSessionsBeforeClose).to.not.be.empty; | ||
expect(idleSessionsAfterClose).to.be.empty; | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Server resource: Transactions', () => { | ||
describe('after a clientSession is created and used', () => { | ||
it.skip('the server-side transaction is cleaned up by client.close()', async function () {}); | ||
it('the server-side transaction is cleaned up by client.close()', async function () { | ||
expect(idleSessionsBeforeClose[0].transaction.txnNumber).to.not.null; | ||
expect(idleSessionsAfterClose).to.be.empty; | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
@@ -632,7 +690,47 @@ describe.skip('MongoClient.close() Integration', () => { | |
|
||
describe('Server resource: Cursor', () => { | ||
describe('after cursors are created', () => { | ||
it.skip('all active server-side cursors are closed by client.close()', async function () {}); | ||
let client; | ||
let coll; | ||
let cursor; | ||
|
||
beforeEach(async function () { | ||
client = this.configuration.newClient(); | ||
coll = client.db('db').collection('coll'); | ||
}); | ||
|
||
afterEach(async function () { | ||
await client?.close(); | ||
await cursor?.close(); | ||
}); | ||
|
||
it('all active server-side cursors are closed by client.close()', async function () { | ||
const getCursors = async () => { | ||
const res = await client | ||
.db() | ||
.admin() | ||
.command({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (optional): Neal added const result = await client.db('admin').runCursorCommand({ aggregate: .... }).toArray();
return result.filter(
r => r.type === 'idleCursor' || (r.type === 'op' && r.desc === 'getMore')
); |
||
aggregate: 1, | ||
cursor: { batchSize: 10 }, | ||
pipeline: [{ $currentOp: { idleCursors: true } }] | ||
}); | ||
return res.cursor.firstBatch.filter( | ||
r => r.type === 'idleCursor' || (r.type === 'op' && r.desc === 'getMore') | ||
); | ||
}; | ||
|
||
await coll.insertMany([{ a: 1 }, { b: 2 }, { c: 3 }]); | ||
cursor = await coll.find(); | ||
|
||
// assert creation | ||
expect(await getCursors()).to.not.be.empty; | ||
|
||
await client.close(); | ||
await client.connect(); | ||
|
||
// assert clean-up | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: We pass all cases already except cursors already. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the other test cases be unskipped then? |
||
expect(await getCursors()).to.be.empty; | ||
}); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional: this is the sort of thing for which we'd usually use a utilClient. If we use a separate client, we keep the client used for testing separate from the client we use to collect cluster data. It also avoids reopening the client after closing it in the test (line 729).