|
1 | 1 | /* eslint-disable @typescript-eslint/no-empty-function */
|
| 2 | +import { expect } from 'chai'; |
| 3 | + |
2 | 4 | import { type TestConfiguration } from '../../tools/runner/config';
|
3 | 5 | import { runScriptAndGetProcessInfo } from './resource_tracking_script_builder';
|
4 | 6 |
|
@@ -500,29 +502,85 @@ describe.skip('MongoClient.close() Integration', () => {
|
500 | 502 | });
|
501 | 503 |
|
502 | 504 | describe('ClientSession (Implicit)', () => {
|
| 505 | + let idleSessionsBeforeClose; |
| 506 | + let idleSessionsAfterClose; |
| 507 | + |
| 508 | + beforeEach(async function () { |
| 509 | + const client = this.configuration.newClient(); |
| 510 | + await client.connect(); |
| 511 | + const session = client.startSession({ explicit: false }); |
| 512 | + session.startTransaction(); |
| 513 | + await client.db('db').collection('collection').insertOne({ x: 1 }, { session }); |
| 514 | + |
| 515 | + const opBefore = await client.db().admin().command({ currentOp: 1 }); |
| 516 | + idleSessionsBeforeClose = opBefore.inprog.filter(s => s.type === 'idleSession'); |
| 517 | + |
| 518 | + await client.close(); |
| 519 | + await client.connect(); |
| 520 | + |
| 521 | + const opAfter = await client.db().admin().command({ currentOp: 1 }); |
| 522 | + idleSessionsAfterClose = opAfter.inprog.filter(s => s.type === 'idleSession'); |
| 523 | + |
| 524 | + await client.close(); |
| 525 | + }); |
| 526 | + |
503 | 527 | describe('Server resource: LSID/ServerSession', () => {
|
504 | 528 | describe('after a clientSession is implicitly created and used', () => {
|
505 |
| - it.skip('the server-side ServerSession is cleaned up by client.close()', async function () {}); |
| 529 | + it('the server-side ServerSession is cleaned up by client.close()', async function () { |
| 530 | + expect(idleSessionsBeforeClose).to.not.be.empty; |
| 531 | + expect(idleSessionsAfterClose).to.be.empty; |
| 532 | + }); |
506 | 533 | });
|
507 | 534 | });
|
508 | 535 |
|
509 | 536 | describe('Server resource: Transactions', () => {
|
510 | 537 | describe('after a clientSession is implicitly created and used', () => {
|
511 |
| - it.skip('the server-side transaction is cleaned up by client.close()', async function () {}); |
| 538 | + it('the server-side transaction is cleaned up by client.close()', async function () { |
| 539 | + expect(idleSessionsBeforeClose[0].transaction.txnNumber).to.not.null; |
| 540 | + expect(idleSessionsAfterClose).to.be.empty; |
| 541 | + }); |
512 | 542 | });
|
513 | 543 | });
|
514 | 544 | });
|
515 | 545 |
|
516 | 546 | describe('ClientSession (Explicit)', () => {
|
| 547 | + let idleSessionsBeforeClose; |
| 548 | + let idleSessionsAfterClose; |
| 549 | + |
| 550 | + beforeEach(async function () { |
| 551 | + const client = this.configuration.newClient(); |
| 552 | + await client.connect(); |
| 553 | + const session = client.startSession(); |
| 554 | + session.startTransaction(); |
| 555 | + await client.db('db').collection('collection').insertOne({ x: 1 }, { session }); |
| 556 | + |
| 557 | + const opBefore = await client.db().admin().command({ currentOp: 1 }); |
| 558 | + idleSessionsBeforeClose = opBefore.inprog.filter(s => s.type === 'idleSession'); |
| 559 | + |
| 560 | + await client.close(); |
| 561 | + await client.connect(); |
| 562 | + |
| 563 | + const opAfter = await client.db().admin().command({ currentOp: 1 }); |
| 564 | + idleSessionsAfterClose = opAfter.inprog.filter(s => s.type === 'idleSession'); |
| 565 | + |
| 566 | + await client.close(); |
| 567 | + }); |
| 568 | + |
517 | 569 | describe('Server resource: LSID/ServerSession', () => {
|
518 | 570 | describe('after a clientSession is created and used', () => {
|
519 |
| - it.skip('the server-side ServerSession is cleaned up by client.close()', async function () {}); |
| 571 | + it('the server-side ServerSession is cleaned up by client.close()', async function () { |
| 572 | + expect(idleSessionsBeforeClose).to.not.be.empty; |
| 573 | + expect(idleSessionsAfterClose).to.be.empty; |
| 574 | + }); |
520 | 575 | });
|
521 | 576 | });
|
522 | 577 |
|
523 | 578 | describe('Server resource: Transactions', () => {
|
524 | 579 | describe('after a clientSession is created and used', () => {
|
525 |
| - it.skip('the server-side transaction is cleaned up by client.close()', async function () {}); |
| 580 | + it('the server-side transaction is cleaned up by client.close()', async function () { |
| 581 | + expect(idleSessionsBeforeClose[0].transaction.txnNumber).to.not.null; |
| 582 | + expect(idleSessionsAfterClose).to.be.empty; |
| 583 | + }); |
526 | 584 | });
|
527 | 585 | });
|
528 | 586 | });
|
@@ -632,7 +690,47 @@ describe.skip('MongoClient.close() Integration', () => {
|
632 | 690 |
|
633 | 691 | describe('Server resource: Cursor', () => {
|
634 | 692 | describe('after cursors are created', () => {
|
635 |
| - it.skip('all active server-side cursors are closed by client.close()', async function () {}); |
| 693 | + let client; |
| 694 | + let coll; |
| 695 | + let cursor; |
| 696 | + |
| 697 | + beforeEach(async function () { |
| 698 | + client = this.configuration.newClient(); |
| 699 | + coll = client.db('db').collection('coll'); |
| 700 | + }); |
| 701 | + |
| 702 | + afterEach(async function () { |
| 703 | + await client?.close(); |
| 704 | + await cursor?.close(); |
| 705 | + }); |
| 706 | + |
| 707 | + it('all active server-side cursors are closed by client.close()', async function () { |
| 708 | + const getCursors = async () => { |
| 709 | + const res = await client |
| 710 | + .db() |
| 711 | + .admin() |
| 712 | + .command({ |
| 713 | + aggregate: 1, |
| 714 | + cursor: { batchSize: 10 }, |
| 715 | + pipeline: [{ $currentOp: { idleCursors: true } }] |
| 716 | + }); |
| 717 | + return res.cursor.firstBatch.filter( |
| 718 | + r => r.type === 'idleCursor' || (r.type === 'op' && r.desc === 'getMore') |
| 719 | + ); |
| 720 | + }; |
| 721 | + |
| 722 | + await coll.insertMany([{ a: 1 }, { b: 2 }, { c: 3 }]); |
| 723 | + cursor = await coll.find(); |
| 724 | + |
| 725 | + // assert creation |
| 726 | + expect(await getCursors()).to.not.be.empty; |
| 727 | + |
| 728 | + await client.close(); |
| 729 | + await client.connect(); |
| 730 | + |
| 731 | + // assert clean-up |
| 732 | + expect(await getCursors()).to.be.empty; |
| 733 | + }); |
636 | 734 | });
|
637 | 735 | });
|
638 | 736 | });
|
0 commit comments