From f0394f91e982a51b0fab3fa66d7109eff270b1d4 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Wed, 28 Dec 2022 13:40:20 +0000 Subject: [PATCH] fix unstable ws test handler + improve logging --- test/spot/ws.public.v3.test.ts | 25 +++++++++---------- .../ws.public.perp.usdc.test.ts | 4 ++- .../ws.public.perp.usdt.test.ts | 5 ++-- test/usdc/perpetual/ws.public.test.ts | 1 + 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/test/spot/ws.public.v3.test.ts b/test/spot/ws.public.v3.test.ts index 43377cc..bea6951 100644 --- a/test/spot/ws.public.v3.test.ts +++ b/test/spot/ws.public.v3.test.ts @@ -58,18 +58,6 @@ describe('Public Spot V3 Websocket Client', () => { req_id: wsTopic, }); - expect(wsUpdatePromise).resolves.toMatchObject({ - data: { - a: expect.any(Array), - b: expect.any(Array), - s: symbol, - t: expect.any(Number), - }, - topic: wsTopic, - ts: expect.any(Number), - type: 'delta', - }); - wsClient.subscribe(wsTopic); try { @@ -82,9 +70,20 @@ describe('Public Spot V3 Websocket Client', () => { } try { - await wsUpdatePromise; + expect(await wsUpdatePromise).toMatchObject({ + data: { + a: expect.any(Array), + b: expect.any(Array), + s: symbol, + t: expect.any(Number), + }, + topic: wsTopic, + ts: expect.any(Number), + type: 'snapshot', + }); } catch (e) { console.error(`Wait for "${wsTopic}" event exception: `, e); + expect(e).toBeFalsy(); } }); }); diff --git a/test/unified-margin/ws.public.perp.usdc.test.ts b/test/unified-margin/ws.public.perp.usdc.test.ts index 86247f7..9abd3c7 100644 --- a/test/unified-margin/ws.public.perp.usdc.test.ts +++ b/test/unified-margin/ws.public.perp.usdc.test.ts @@ -70,12 +70,14 @@ describe('Public Unified Margin Websocket Client (Perps - USDC)', () => { s: 'BTCUSDT', u: expect.any(Number), }, + wsKey: WS_KEY_MAP.unifiedPerpUSDTPublic, topic: 'orderbook.25.BTCUSDC', ts: expect.any(Number), type: 'snapshot', - wsKey: WS_KEY_MAP.unifiedPerpUSDTPublic, }); } catch (e) { + console.error('unified margin perp ws public error: ', e); + // no data expect(e).toBeFalsy(); } diff --git a/test/unified-margin/ws.public.perp.usdt.test.ts b/test/unified-margin/ws.public.perp.usdt.test.ts index 6880524..8bb1017 100644 --- a/test/unified-margin/ws.public.perp.usdt.test.ts +++ b/test/unified-margin/ws.public.perp.usdt.test.ts @@ -49,7 +49,7 @@ describe('Public Unified Margin Websocket Client (Perps - USDT)', () => { const wsUpdatePromise = waitForSocketEvent(wsClient, 'update'); // USDT should be detected and automatically routed through the USDT connection - const topic = 'orderbook.25.BTCUSDT'; + const topic = 'orderbook.1.BTCUSDT'; wsClient.subscribe(topic); try { @@ -74,10 +74,11 @@ describe('Public Unified Margin Websocket Client (Perps - USDT)', () => { }, topic: topic, ts: expect.any(Number), - type: 'snapshot', wsKey: WS_KEY_MAP.unifiedPerpUSDTPublic, + type: 'snapshot', }); } catch (e) { + console.error('unified margin perp usdt orderbook test fail', e); // no data expect(e).toBeFalsy(); } diff --git a/test/usdc/perpetual/ws.public.test.ts b/test/usdc/perpetual/ws.public.test.ts index c858f07..4c7dded 100644 --- a/test/usdc/perpetual/ws.public.test.ts +++ b/test/usdc/perpetual/ws.public.test.ts @@ -69,6 +69,7 @@ describe('Public USDC Perp Websocket Client', () => { type: 'snapshot', }); } catch (e) { + console.error('usdc perp ws public error: ', e); // no data expect(e).toBeFalsy(); }