From 3b59a122eeeb941b090709eb000f1110f66a4039 Mon Sep 17 00:00:00 2001 From: Warren James Date: Thu, 15 Dec 2022 16:04:24 -0500 Subject: [PATCH] test(NODE-4834): Update tests to be more coherent --- test/unit/cmap/connection.test.ts | 35 ++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/test/unit/cmap/connection.test.ts b/test/unit/cmap/connection.test.ts index 8c6fe98ddc..aeeb59947b 100644 --- a/test/unit/cmap/connection.test.ts +++ b/test/unit/cmap/connection.test.ts @@ -620,15 +620,44 @@ describe('new Connection()', function () { expect(driverSocket.end).to.have.been.calledOnce; }); - it('does not call stream.end after onClose, onTimeout, or onError', () => { + it('calls stream.end exactly once when onError is called', () => { messageStream.emit('error'); clock.tick(1); expect(connection.onError).to.have.been.calledOnce; + connection.destroy({ force: false }); + clock.tick(1); + expect(driverSocket.destroy).to.not.have.been.called; + expect(driverSocket.end).to.have.been.calledOnce; + }); + + it('calls stream.end exactly once when onClose is called', () => { + driverSocket.emit('close'); + clock.tick(1); + expect(connection.onClose).to.have.been.calledOnce; + connection.destroy({ force: false }); + clock.tick(1); + expect(driverSocket.destroy).to.not.have.been.called; + expect(driverSocket.end).to.have.been.calledOnce; + }); + + it('calls stream.end exactly once when onTimeout is called', () => { + driverSocket.emit('timeout'); clock.tick(1); - expect(driverSocket.destroy).to.not.have.been.calledOnce; + expect(connection.onTimeout).to.have.been.calledOnce; + connection.destroy({ force: false }); + clock.tick(1); + expect(driverSocket.destroy).to.not.have.been.called; + expect(driverSocket.end).to.have.been.calledOnce; + }); + + it('calls stream.end exactly once when destroy is called multiple times', () => { + connection.destroy({ force: false }); + connection.destroy({ force: false }); + connection.destroy({ force: false }); connection.destroy({ force: false }); clock.tick(1); - expect(driverSocket.end).to.have.been.called; + expect(driverSocket.destroy).to.not.have.been.called; + expect(driverSocket.end).to.have.been.calledOnce; }); it('does not call stream.end if options.force == true', () => {