|
1 | 1 | /* eslint-disable @typescript-eslint/no-empty-function */ |
| 2 | +import { expect } from 'chai'; |
| 3 | +import { MongoClient } from '../../mongodb'; |
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.only('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; |
@@ -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,32 @@ 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 cursor; |
| 695 | + |
| 696 | + afterEach(async function () { |
| 697 | + await client?.close(); |
| 698 | + await cursor?.close(); |
| 699 | + }); |
| 700 | + |
| 701 | + it.only('all active server-side cursors are closed by client.close()', async function () { |
| 702 | + client = this.configuration.newClient(); |
| 703 | + const coll = client.db('db').collection('coll'); |
| 704 | + await coll.insertMany([{ a: 1 }, { b: 1 }]); |
| 705 | + cursor = await coll.find(); |
| 706 | + await cursor.next(); |
| 707 | + |
| 708 | + const before = await client.db().admin().command({ aggregate: 1, cursor: {}, pipeline: [ { $currentOp: { idleCursors: true, } }] }); |
| 709 | + const beforeOp = await before.cursor.toArray(); |
| 710 | + //const cursorsBefore = opBefore.inprog.filter(r => r.type === 'idleCursor'); |
| 711 | + //expect(cursorsBefore).to.not.be.empty; |
| 712 | + |
| 713 | + await client.close(); |
| 714 | + await client.connect(); |
| 715 | + |
| 716 | + const opAfter = await client.db().admin().command({ aggregate: 1, cursor: {}, pipeline: [ { $currentOp: { idleCursors: true } }] }); |
| 717 | + //expect(cursorsAfter).to.be.empty; |
| 718 | + }); |
636 | 719 | }); |
637 | 720 | }); |
638 | 721 | }); |
0 commit comments