ws test stability fixes

This commit is contained in:
tiagosiebler
2022-09-16 00:43:57 +01:00
parent 921152fa3b
commit 2ada7eb664
3 changed files with 6 additions and 9 deletions

View File

@@ -321,6 +321,7 @@ export class WebsocketClient extends EventEmitter {
private parseWsError(context: string, error: any, wsKey: WsKey) { private parseWsError(context: string, error: any, wsKey: WsKey) {
if (!error.message) { if (!error.message) {
this.logger.error(`${context} due to unexpected error: `, error); this.logger.error(`${context} due to unexpected error: `, error);
this.emit('error', error);
return; return;
} }
@@ -339,14 +340,13 @@ export class WebsocketClient extends EventEmitter {
); );
break; break;
} }
this.emit('error', error);
} }
/** /**
* Return params required to make authorized request * Return params required to make authorized request
*/ */
private async getAuthParams(wsKey: WsKey): Promise<string> { private async getAuthParams(wsKey: WsKey): Promise<string> {
const { key, secret } = this.options;
if (PUBLIC_WS_KEYS.includes(wsKey)) { if (PUBLIC_WS_KEYS.includes(wsKey)) {
this.logger.debug('Starting public only websocket client.', { this.logger.debug('Starting public only websocket client.', {
...loggerCategory, ...loggerCategory,

View File

@@ -34,12 +34,11 @@ describe('Private Inverse Perps Websocket Client', () => {
badClient.connectPrivate(); badClient.connectPrivate();
expect(wsOpenPromise).rejects.toMatch('Failed to receive');
try { try {
await Promise.all([wsOpenPromise]); expect(await wsOpenPromise).toMatch('Failed to receive');
} catch (e) { } catch (e) {
// console.error() // console.error()
expect(e?.message).toStrictEqual('Unexpected server response: 401');
} }
badClient.closeAll(); badClient.closeAll();
}); });

View File

@@ -34,12 +34,10 @@ describe('Private Linear Perps Websocket Client', () => {
badClient.connectPrivate(); badClient.connectPrivate();
expect(wsOpenPromise).rejects.toMatch('Failed to receive');
try { try {
await Promise.all([wsOpenPromise]); expect(await wsOpenPromise).toMatch('Failed to receive');
} catch (e) { } catch (e) {
// console.error() expect(e?.message).toStrictEqual('Unexpected server response: 401');
} }
badClient.closeAll(); badClient.closeAll();
}); });