Skip to content

Commit

Permalink
$currentOp idleCursors needs >= 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
aditi-khare-mongoDB committed Jan 30, 2025
1 parent 3c98214 commit f53ecc6
Showing 1 changed file with 38 additions and 28 deletions.
66 changes: 38 additions & 28 deletions test/integration/node-specific/client_close.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,12 @@ describe('MongoClient.close() Integration', () => {
});

describe('Server resource: Cursor', () => {
const metadata: MongoDBMetadataUI = {
requires: {
mongodb: '>=4.2.0'
}
};

describe('after cursors are created', () => {
let client: MongoClient;
let coll: Collection;
Expand Down Expand Up @@ -726,38 +732,42 @@ describe('MongoClient.close() Integration', () => {
await cursor?.close();
});

it('all active server-side cursors are closed by client.close()', async function () {
const getCursors = async () => {
const res = await utilClient
.db()
.admin()
.command({
aggregate: 1,
cursor: {},
pipeline: [{ $currentOp: { idleCursors: true } }]
});
return res.cursor.firstBatch.filter(
r => r.type === 'idleCursor' || (r.type === 'op' && r.desc === 'getMore')
);
};
it(
'all active server-side cursors are closed by client.close()',
metadata,
async function () {
const getCursors = async () => {
const res = await utilClient
.db()
.admin()
.command({
aggregate: 1,
cursor: {},
pipeline: [{ $currentOp: { idleCursors: true } }]
});
return res.cursor.firstBatch.filter(
r => r.type === 'idleCursor' || (r.type === 'op' && r.desc === 'getMore')
);
};

cursor = coll.find(
{},
{
tailable: true,
awaitData: true
}
);
await cursor.next();
cursor = coll.find(
{},
{
tailable: true,
awaitData: true
}
);
await cursor.next();

// assert creation
expect(await getCursors()).to.not.be.empty;
// assert creation
expect(await getCursors()).to.not.be.empty;

await client.close();
await client.close();

// assert clean-up
expect(await getCursors()).to.be.empty;
});
// assert clean-up
expect(await getCursors()).to.be.empty;
}
);
});
});
});

0 comments on commit f53ecc6

Please sign in to comment.