Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Streaming] change isConnected() to a getter #1488

Merged
merged 2 commits into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
* Abstraction for a generic transport definition.
*/
export interface ITransport {
isConnected(): boolean;
isConnected: boolean;
close();
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class NamedPipeTransport implements ITransportSender, ITransportReceiver
/**
* Returns true if currently connected.
*/
public isConnected(): boolean {
public get isConnected(): boolean {
return !(!this._socket || this._socket.destroyed || this._socket.connecting);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class WebSocketTransport implements ITransportSender, ITransportReceiver
/**
* Returns true if the transport is connected to a socket.
*/
public isConnected(): boolean {
public get isConnected(): boolean {
return this._socket.isConnected;
}

Expand Down
21 changes: 10 additions & 11 deletions libraries/botframework-streaming/tests/NamedPipe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ describe('Streaming Extensions NamedPipe Library Tests', () => {
sock.writable = true;
let transport = new npt.NamedPipeTransport(sock, 'fakeSocket2');
expect(transport).to.be.instanceOf(npt.NamedPipeTransport);
expect(transport.isConnected()).to.be.true;
expect(transport.isConnected).to.be.true;
expect( () => transport.close()).to.not.throw;
});

Expand All @@ -203,9 +203,8 @@ describe('Streaming Extensions NamedPipe Library Tests', () => {
sock.writable = true;
let transport = new npt.NamedPipeTransport(sock, 'fakeSocket3');
expect(transport).to.be.instanceOf(npt.NamedPipeTransport);
expect( transport.close()).to.not.throw;
let exists = transport.isConnected();
expect(exists).to.be.false;
expect(transport.close()).to.not.throw;
expect(transport.isConnected).to.be.false;
});

it('writes to the socket', () => {
Expand All @@ -215,7 +214,7 @@ describe('Streaming Extensions NamedPipe Library Tests', () => {
sock.writable = true;
let transport = new npt.NamedPipeTransport(sock, 'fakeSocket4');
expect(transport).to.be.instanceOf(npt.NamedPipeTransport);
expect(transport.isConnected()).to.be.true;
expect(transport.isConnected).to.be.true;
let buff = Buffer.from('hello', 'utf8');
let sent = transport.send(buff);
expect(sent).to.equal(5);
Expand All @@ -229,7 +228,7 @@ describe('Streaming Extensions NamedPipe Library Tests', () => {
sock.writable = true;
let transport = new npt.NamedPipeTransport(sock, 'fakeSocket5');
expect(transport).to.be.instanceOf(npt.NamedPipeTransport);
expect(transport.isConnected()).to.be.true;
expect(transport.isConnected).to.be.true;
sock.writable = false;
let buff = Buffer.from('hello', 'utf8');
let sent = transport.send(buff);
Expand All @@ -244,7 +243,7 @@ describe('Streaming Extensions NamedPipe Library Tests', () => {
sock.writable = true;
let transport = new npt.NamedPipeTransport(sock, 'fakeSocket5');
expect(transport).to.be.instanceOf(npt.NamedPipeTransport);
expect(transport.isConnected()).to.be.true;
expect(transport.isConnected).to.be.true;
expect(transport.receive(5)).to.throw;
expect( () => transport.close()).to.not.throw;
});
Expand All @@ -256,7 +255,7 @@ describe('Streaming Extensions NamedPipe Library Tests', () => {
sock.writable = true;
let transport = new npt.NamedPipeTransport(sock);
expect(transport).to.be.instanceOf(npt.NamedPipeTransport);
expect(transport.isConnected()).to.be.true;
expect(transport.isConnected).to.be.true;
transport.receive(12).catch();
transport.socketReceive(Buffer.from('Hello World!', 'utf8'));

Expand All @@ -271,7 +270,7 @@ describe('Streaming Extensions NamedPipe Library Tests', () => {
sock.writable = true;
let transport = new npt.NamedPipeTransport(sock, 'fakeSocket6');
expect(transport).to.be.instanceOf(npt.NamedPipeTransport);
expect(transport.isConnected()).to.be.true;
expect(transport.isConnected).to.be.true;
transport.socketClose();
expect(transport._active).to.be.null;
expect(transport._activeReceiveResolve).to.be.null;
Expand All @@ -288,7 +287,7 @@ describe('Streaming Extensions NamedPipe Library Tests', () => {
sock.writable = true;
let transport = new npt.NamedPipeTransport(sock, 'fakeSocket6');
expect(transport).to.be.instanceOf(npt.NamedPipeTransport);
expect(transport.isConnected()).to.be.true;
expect(transport.isConnected).to.be.true;
transport.socketError();
expect(transport._active).to.be.null;
expect(transport._activeReceiveResolve).to.be.null;
Expand All @@ -305,7 +304,7 @@ describe('Streaming Extensions NamedPipe Library Tests', () => {
sock.writable = true;
let transport = new npt.NamedPipeTransport(sock, 'fakeSocket6');
expect(transport).to.be.instanceOf(npt.NamedPipeTransport);
expect(transport.isConnected()).to.be.true;
expect(transport.isConnected).to.be.true;
let buff = Buffer.from('hello', 'utf8');
expect(transport.socketReceive(buff)).to.not.throw;
});
Expand Down
21 changes: 10 additions & 11 deletions libraries/botframework-streaming/tests/WebSocket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('Streaming Extensions WebSocket Library Tests', () => {
sock.writable = true;
let transport = new wst.WebSocketTransport(sock);
expect(transport).to.be.instanceOf(wst.WebSocketTransport);
expect(transport.isConnected()).to.be.true;
expect(transport.isConnected).to.be.true;
expect( () => transport.close()).to.not.throw;
});

Expand All @@ -43,9 +43,8 @@ describe('Streaming Extensions WebSocket Library Tests', () => {
sock.writable = true;
let transport = new wst.WebSocketTransport(sock);
expect(transport).to.be.instanceOf(wst.WebSocketTransport);
expect( transport.close()).to.not.throw;
let exists = transport.isConnected();
expect(exists).to.be.false;
expect(transport.close()).to.not.throw;
expect(transport.isConnected).to.be.false;
});

it('writes to the socket', () => {
Expand All @@ -55,7 +54,7 @@ describe('Streaming Extensions WebSocket Library Tests', () => {
sock.writable = true;
let transport = new wst.WebSocketTransport(sock);
expect(transport).to.be.instanceOf(wst.WebSocketTransport);
expect(transport.isConnected()).to.be.true;
expect(transport.isConnected).to.be.true;
let buff = Buffer.from('hello', 'utf8');
let sent = transport.send(buff);
expect(sent).to.equal(5);
Expand All @@ -69,7 +68,7 @@ describe('Streaming Extensions WebSocket Library Tests', () => {
sock.writable = true;
let transport = new wst.WebSocketTransport(sock);
expect(transport).to.be.instanceOf(wst.WebSocketTransport);
expect(transport.isConnected()).to.be.true;
expect(transport.isConnected).to.be.true;
sock.writable = false;
sock.connected = false;
let buff = Buffer.from('hello', 'utf8');
Expand All @@ -85,7 +84,7 @@ describe('Streaming Extensions WebSocket Library Tests', () => {
sock.writable = true;
let transport = new wst.WebSocketTransport(sock);
expect(transport).to.be.instanceOf(wst.WebSocketTransport);
expect(transport.isConnected()).to.be.true;
expect(transport.isConnected).to.be.true;
expect(transport.receive(5)).to.throw;
expect( () => transport.close()).to.not.throw;
});
Expand All @@ -97,7 +96,7 @@ describe('Streaming Extensions WebSocket Library Tests', () => {
sock.writable = true;
let transport = new wst.WebSocketTransport(sock);
expect(transport).to.be.instanceOf(wst.WebSocketTransport);
expect(transport.isConnected()).to.be.true;
expect(transport.isConnected).to.be.true;
transport.receive(12).catch();
transport.onReceive(Buffer.from('{"VERB":"POST", "PATH":"somewhere/something"}', 'utf8'));

Expand All @@ -111,7 +110,7 @@ describe('Streaming Extensions WebSocket Library Tests', () => {
sock.writable = true;
let transport = new wst.WebSocketTransport(sock);
expect(transport).to.be.instanceOf(wst.WebSocketTransport);
expect(transport.isConnected()).to.be.true;
expect(transport.isConnected).to.be.true;
transport.onClose();
expect(transport._active).to.be.null;
expect(transport._activeReceiveResolve).to.be.null;
Expand All @@ -128,7 +127,7 @@ describe('Streaming Extensions WebSocket Library Tests', () => {
sock.writable = true;
let transport = new wst.WebSocketTransport(sock);
expect(transport).to.be.instanceOf(wst.WebSocketTransport);
expect(transport.isConnected()).to.be.true;
expect(transport.isConnected).to.be.true;
transport.onError();
expect(transport._active).to.be.null;
expect(transport._activeReceiveResolve).to.be.null;
Expand All @@ -145,7 +144,7 @@ describe('Streaming Extensions WebSocket Library Tests', () => {
sock.writable = true;
let transport = new wst.WebSocketTransport(sock);
expect(transport).to.be.instanceOf(wst.WebSocketTransport);
expect(transport.isConnected()).to.be.true;
expect(transport.isConnected).to.be.true;
let buff = Buffer.from('hello', 'utf8');
expect(transport.onReceive(buff)).to.not.throw;
});
Expand Down