Skip to content

Commit

Permalink
test(NODE-4834): Update tests to be more coherent
Browse files Browse the repository at this point in the history
  • Loading branch information
W-A-James committed Dec 15, 2022
1 parent 860d741 commit 3b59a12
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions test/unit/cmap/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 3b59a12

Please sign in to comment.