Skip to content

Commit

Permalink
Handle connect() when already connected
Browse files Browse the repository at this point in the history
  • Loading branch information
bergie committed Mar 21, 2018
1 parent 5cfbbcb commit 4bb5565
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class FbpClient extends EventEmitter {

connect() {
return timedPromise((resolve, reject) => {
if (this.isConnected()) {
resolve(this.definition);
return;
}
let onError = null;
const onRuntime = (message) => {
if (message.command !== 'runtime') {
Expand Down
16 changes: 16 additions & 0 deletions spec/noflo-nodejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ describe('FBP Client with noflo-nodejs', () => {
it('should have updated runtime definition type', () => {
expect(client.definition.type).to.equal('noflo-nodejs');
});
it('should be able to connect again without side-effects', () => {
client.adapter.__spec = true;
return client.connect()
.then(() => {
expect(client.adapter.__spec).to.equal(true);
delete client.adapter.__spec;
});
});
});
describe('when connected', () => {
it('should be possible to get graph sources', () => {
Expand Down Expand Up @@ -84,5 +92,13 @@ describe('FBP Client with noflo-nodejs', () => {
it('should be marked as disconnected', () => {
expect(client.isConnected()).to.not.equal(true);
});
it('should be able to disconnect again without side-effects', () => {
client.adapter.__spec = true;
return client.disconnect()
.then(() => {
expect(client.adapter.__spec).to.equal(true);
delete client.adapter.__spec;
});
});
});
});

0 comments on commit 4bb5565

Please sign in to comment.