Assign event listener to socket close event on open before attempting post-open logic (#1186)

* Assign event listener to socket close event on open before attempting to execute post-connection logic, prottects possible unhandled rejection in disconnect
* Remove try/catch for linting failure
* Up timeout for CI failure
* Feedback emit error for disconnection failure on connect failure
* Feedback ignore error on disconnect, propagate root cause
* Feedback add extra test check for expected error on connect
* Feedback remove setTimeout for await reconnect
This commit is contained in:
Nicholas Smith
2020-01-28 09:08:47 -05:00
committed by Hans Bergren
parent 97ca0f0b21
commit c17827e030
2 changed files with 29 additions and 12 deletions

View File

@@ -590,6 +590,24 @@ describe('Connection', function() {
}
)
it('should clean up websocket connection if error after websocket is opened', async function() {
await this.api.disconnect();
// fail on connection
this.api.connection._subscribeToLedger = async () => {
throw new Error('error on _subscribeToLedger')
}
try {
await this.api.connect();
throw new Error('expected connect() to reject, but it resolved')
} catch (err) {
assert(err.message === 'error on _subscribeToLedger');
// _ws.close event listener should have cleaned up the socket when disconnect _ws.close is run on connection error
// do not fail on connection anymore
this.api.connection._subscribeToLedger = async () => {}
await this.api.connection.reconnect();
}
})
it('should try to reconnect on empty subscribe response on reconnect', function(done) {
this.timeout(23000)
this.api.on('error', error => {