Skip to content

Commit 229253f

Browse files
requested changes 2
1 parent e5546c1 commit 229253f

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

test/integration/node-specific/mongo_client.test.ts

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -724,22 +724,49 @@ describe('class MongoClient', function () {
724724
});
725725

726726
context('concurrent calls', () => {
727+
let topologyClosedSpy;
728+
beforeEach(async function () {
729+
await client.connect();
730+
const coll = client.db('db').collection('concurrentCalls');
731+
const session = client.startSession();
732+
await coll.findOne({}, { session: session });
733+
topologyClosedSpy = sinon.spy(Topology.prototype, 'close');
734+
});
735+
736+
afterEach(async function () {
737+
sinon.restore();
738+
});
739+
727740
context('when two concurrent calls to close() occur', () => {
728-
it('no error is thrown', async function () {
729-
expect(() => Promise.all([client.close(), client.close()])).to.not.throw;
741+
it('does not throw', async function () {
742+
await Promise.all([client.close(), client.close()]);
743+
});
744+
745+
it('clean-up logic is performed only once', async function () {
746+
await Promise.all([client.close(), client.close()]);
747+
expect(topologyClosedSpy).to.have.been.calledOnce;
730748
});
731749
});
732750

733751
context('when more than two concurrent calls to close() occur', () => {
734-
it('no error is thrown', async function () {
735-
expect(() =>
736-
Promise.all([client.close(), client.close(), client.close(), client.close()])
737-
).to.not.throw;
752+
it('does not throw', async function () {
753+
await Promise.all([client.close(), client.close(), client.close(), client.close()]);
754+
});
755+
756+
it('clean-up logic is performed only once', async function () {
757+
await client.connect();
758+
await Promise.all([
759+
client.close(),
760+
client.close(),
761+
client.close(),
762+
client.close(),
763+
client.close()
764+
]);
765+
expect(topologyClosedSpy).to.have.been.calledOnce;
738766
});
739767
});
740768

741769
it('when connect rejects lock is released regardless', async function () {
742-
await client.connect();
743770
expect(client.topology?.isConnected()).to.be.true;
744771

745772
const closeStub = sinon.stub(client, 'close');

0 commit comments

Comments
 (0)