|
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 |
|
5 | | -describe.skip('MongoClient.close() Integration', () => { |
| 7 | +describe('MongoClient.close() Integration', () => { |
6 | 8 | // note: these tests are set-up in accordance of the resource ownership tree |
7 | 9 |
|
8 | 10 | let config: TestConfiguration; |
@@ -452,29 +454,85 @@ describe.skip('MongoClient.close() Integration', () => { |
452 | 454 | }); |
453 | 455 |
|
454 | 456 | describe('ClientSession (Implicit)', () => { |
| 457 | + let idleSessionsBeforeClose; |
| 458 | + let idleSessionsAfterClose; |
| 459 | + |
| 460 | + beforeEach(async function () { |
| 461 | + const client = this.configuration.newClient(); |
| 462 | + await client.connect(); |
| 463 | + const session = client.startSession({ explicit: false }); |
| 464 | + session.startTransaction(); |
| 465 | + await client.db('db').collection('collection').insertOne({ x: 1 }, { session }); |
| 466 | + |
| 467 | + const opBefore = await client.db().admin().command({ currentOp: 1 }); |
| 468 | + idleSessionsBeforeClose = opBefore.inprog.filter(s => s.type === 'idleSession'); |
| 469 | + |
| 470 | + await client.close(); |
| 471 | + await client.connect(); |
| 472 | + |
| 473 | + const opAfter = await client.db().admin().command({ currentOp: 1 }); |
| 474 | + idleSessionsAfterClose = opAfter.inprog.filter(s => s.type === 'idleSession'); |
| 475 | + |
| 476 | + await client.close(); |
| 477 | + }); |
| 478 | + |
455 | 479 | describe('Server resource: LSID/ServerSession', () => { |
456 | 480 | describe('after a clientSession is implicitly created and used', () => { |
457 | | - it.skip('the server-side ServerSession is cleaned up by client.close()', async function () {}); |
| 481 | + it('the server-side ServerSession is cleaned up by client.close()', async function () { |
| 482 | + expect(idleSessionsBeforeClose).to.not.be.empty; |
| 483 | + expect(idleSessionsAfterClose).to.be.empty; |
| 484 | + }); |
458 | 485 | }); |
459 | 486 | }); |
460 | 487 |
|
461 | 488 | describe('Server resource: Transactions', () => { |
462 | 489 | describe('after a clientSession is implicitly created and used', () => { |
463 | | - it.skip('the server-side transaction is cleaned up by client.close()', async function () {}); |
| 490 | + it('the server-side transaction is cleaned up by client.close()', async function () { |
| 491 | + expect(idleSessionsBeforeClose[0].transaction.txnNumber).to.not.null; |
| 492 | + expect(idleSessionsAfterClose).to.be.empty; |
| 493 | + }); |
464 | 494 | }); |
465 | 495 | }); |
466 | 496 | }); |
467 | 497 |
|
468 | 498 | describe('ClientSession (Explicit)', () => { |
| 499 | + let idleSessionsBeforeClose; |
| 500 | + let idleSessionsAfterClose; |
| 501 | + |
| 502 | + beforeEach(async function () { |
| 503 | + const client = this.configuration.newClient(); |
| 504 | + await client.connect(); |
| 505 | + const session = client.startSession(); |
| 506 | + session.startTransaction(); |
| 507 | + await client.db('db').collection('collection').insertOne({ x: 1 }, { session }); |
| 508 | + |
| 509 | + const opBefore = await client.db().admin().command({ currentOp: 1 }); |
| 510 | + idleSessionsBeforeClose = opBefore.inprog.filter(s => s.type === 'idleSession'); |
| 511 | + |
| 512 | + await client.close(); |
| 513 | + await client.connect(); |
| 514 | + |
| 515 | + const opAfter = await client.db().admin().command({ currentOp: 1 }); |
| 516 | + idleSessionsAfterClose = opAfter.inprog.filter(s => s.type === 'idleSession'); |
| 517 | + |
| 518 | + await client.close(); |
| 519 | + }); |
| 520 | + |
469 | 521 | describe('Server resource: LSID/ServerSession', () => { |
470 | 522 | describe('after a clientSession is created and used', () => { |
471 | | - it.skip('the server-side ServerSession is cleaned up by client.close()', async function () {}); |
| 523 | + it('the server-side ServerSession is cleaned up by client.close()', async function () { |
| 524 | + expect(idleSessionsBeforeClose).to.not.be.empty; |
| 525 | + expect(idleSessionsAfterClose).to.be.empty; |
| 526 | + }); |
472 | 527 | }); |
473 | 528 | }); |
474 | 529 |
|
475 | 530 | describe('Server resource: Transactions', () => { |
476 | 531 | describe('after a clientSession is created and used', () => { |
477 | | - it.skip('the server-side transaction is cleaned up by client.close()', async function () {}); |
| 532 | + it('the server-side transaction is cleaned up by client.close()', async function () { |
| 533 | + expect(idleSessionsBeforeClose[0].transaction.txnNumber).to.not.null; |
| 534 | + expect(idleSessionsAfterClose).to.be.empty; |
| 535 | + }); |
478 | 536 | }); |
479 | 537 | }); |
480 | 538 | }); |
@@ -584,7 +642,47 @@ describe.skip('MongoClient.close() Integration', () => { |
584 | 642 |
|
585 | 643 | describe('Server resource: Cursor', () => { |
586 | 644 | describe('after cursors are created', () => { |
587 | | - it.skip('all active server-side cursors are closed by client.close()', async function () {}); |
| 645 | + let client; |
| 646 | + let coll; |
| 647 | + let cursor; |
| 648 | + |
| 649 | + beforeEach(async function () { |
| 650 | + client = this.configuration.newClient(); |
| 651 | + coll = client.db('db').collection('coll'); |
| 652 | + }); |
| 653 | + |
| 654 | + afterEach(async function () { |
| 655 | + await client?.close(); |
| 656 | + await cursor?.close(); |
| 657 | + }); |
| 658 | + |
| 659 | + it('all active server-side cursors are closed by client.close()', async function () { |
| 660 | + const getCursors = async () => { |
| 661 | + const res = await client |
| 662 | + .db() |
| 663 | + .admin() |
| 664 | + .command({ |
| 665 | + aggregate: 1, |
| 666 | + cursor: { batchSize: 10 }, |
| 667 | + pipeline: [{ $currentOp: { idleCursors: true } }] |
| 668 | + }); |
| 669 | + return res.cursor.firstBatch.filter( |
| 670 | + r => r.type === 'idleCursor' || (r.type === 'op' && r.desc === 'getMore') |
| 671 | + ); |
| 672 | + }; |
| 673 | + |
| 674 | + await coll.insertMany([{ a: 1 }, { b: 2 }, { c: 3 }]); |
| 675 | + cursor = await coll.find(); |
| 676 | + |
| 677 | + // assert creation |
| 678 | + expect(await getCursors()).to.not.be.empty; |
| 679 | + |
| 680 | + await client.close(); |
| 681 | + await client.connect(); |
| 682 | + |
| 683 | + // assert clean-up |
| 684 | + expect(await getCursors()).to.be.empty; |
| 685 | + }); |
588 | 686 | }); |
589 | 687 | }); |
590 | 688 | }); |
0 commit comments