Skip to content

Commit

Permalink
test(NODE-4834): Split up tests more cleanly
Browse files Browse the repository at this point in the history
  • Loading branch information
W-A-James committed Dec 16, 2022
1 parent 23755ca commit 878c764
Showing 1 changed file with 41 additions and 17 deletions.
58 changes: 41 additions & 17 deletions test/unit/cmap/connection.test.ts
Expand Up @@ -616,23 +616,6 @@ describe('new Connection()', function () {
clock.restore();
});

it('ends the tcp socket and destroys the messageStream', () => {
connection.destroy({ force: false });
clock.tick(1);
expect(messageStream.destroy).to.have.been.calledOnce;
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.destroy).to.not.have.been.called;
expect(driverSocket.end).to.have.been.calledOnce;
});

context('when options.force == true', function () {
it('calls steam.destroy', () => {
connection.destroy({ force: true });
Expand All @@ -645,6 +628,26 @@ describe('new Connection()', function () {
clock.tick(1);
expect(driverSocket.end).to.not.have.been.called;
});

it('destroys the tcp socket', () => {
connection.destroy({ force: true });
clock.tick(1);
expect(driverSocket.destroy).to.have.been.calledOnce;
});

it('destroys the messageStream', () => {
connection.destroy({ force: true });
clock.tick(1);
expect(messageStream.destroy).to.have.been.calledOnce;
});

it('calls stream.destroy whenever destroy is called ', () => {
connection.destroy({ force: true });
connection.destroy({ force: true });
connection.destroy({ force: true });
clock.tick(1);
expect(driverSocket.destroy).to.have.been.calledThrice;
});
});

context('when options.force == false', function () {
Expand All @@ -659,6 +662,27 @@ describe('new Connection()', function () {
clock.tick(1);
expect(driverSocket.destroy).to.not.have.been.called;
});

it('ends the tcp socket', () => {
connection.destroy({ force: false });
clock.tick(1);
expect(driverSocket.end).to.have.been.calledOnce;
});

it('destroys the messageStream', () => {
connection.destroy({ force: false });
clock.tick(1);
expect(messageStream.destroy).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.calledOnce;
});
});
});
});

0 comments on commit 878c764

Please sign in to comment.