Skip to content

Commit

Permalink
Merge branch 'regevbr-10286'
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Sep 19, 2022
2 parents 99f4ad2 + dc10e24 commit b9ea9a4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/microservices/client/client-tcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ export class ClientTCP extends ClientProxy {
this.isConnected = false;
this.socket = null;
this.connection = undefined;

if (this.routingMap.size > 0) {
const err = new Error('Connection closed');
for (const callback of this.routingMap.values()) {
callback({ err });
}
this.routingMap.clear();
}
}

protected publish(
Expand Down
17 changes: 17 additions & 0 deletions packages/microservices/test/client/client-tcp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,16 @@ describe('ClientTCP', () => {
});
});
describe('close', () => {
let routingMap;
let callback;

beforeEach(() => {
routingMap = new Map<string, Function>();
callback = sinon.spy();
routingMap.set('some id', callback);
(client as any).socket = socket;
(client as any).isConnected = true;
(client as any).routingMap = routingMap;
client.close();
});
it('should end() socket', () => {
Expand All @@ -168,6 +175,16 @@ describe('ClientTCP', () => {
it('should set "socket" to null', () => {
expect((client as any).socket).to.be.null;
});
it('should clear out the routing map', () => {
expect((client as any).routingMap.size).to.be.eq(0);
});
it('should call callbacks', () => {
expect(
callback.calledWith({
err: sinon.match({ message: 'connection to server closed' }),
}),
).to.be.true;
});
});
describe('bindEvents', () => {
it('should bind error event handler', () => {
Expand Down

0 comments on commit b9ea9a4

Please sign in to comment.