@@ -293,6 +293,13 @@ test.serial('reconnects if connection becomes unresponsive', async (t) => {
293293 const base = 'ETH'
294294 const quote = 'DOGE'
295295 const WS_SUBSCRIPTION_UNRESPONSIVE_TTL = 1000
296+ process . env [ 'METRICS_ENABLED' ] = 'true'
297+ eaMetrics . clear ( )
298+
299+ const labels = {
300+ feed_id : "{'base':'eth','quote':'doge'}" ,
301+ subscription_key : "test-{'base':'eth','quote':'doge'}" ,
302+ }
296303
297304 // Mock WS
298305 mockWebSocketProvider ( WebSocketClassProvider )
@@ -304,6 +311,12 @@ test.serial('reconnects if connection becomes unresponsive', async (t) => {
304311 connectionCounter ++
305312 socket . on ( 'message' , ( ) => {
306313 messageCounter ++
314+ socket . send (
315+ JSON . stringify ( {
316+ pair : `${ base } /${ quote } ` ,
317+ value : price ,
318+ } ) ,
319+ )
307320 } )
308321 } )
309322
@@ -314,21 +327,45 @@ test.serial('reconnects if connection becomes unresponsive', async (t) => {
314327
315328 const testAdapter = await TestAdapter . startWithMockedCache ( adapter , t . context )
316329
317- const error = await testAdapter . request ( {
318- base,
319- quote,
330+ await testAdapter . startBackgroundExecuteThenGetResponse ( t , {
331+ requestData : { base, quote } ,
332+ expectedResponse : {
333+ data : {
334+ result : price ,
335+ } ,
336+ result : price ,
337+ statusCode : 200 ,
338+ } ,
320339 } )
321- t . is ( error . statusCode , 504 )
322340
323- // The WS connection should not send any messages to the EA, so we advance the clock until
324- // we reach the point where the EA will consider it unhealthy and reconnect.
325- await runAllUntilTime ( t . context . clock , BACKGROUND_EXECUTE_MS_WS * 2 + 100 )
341+ let metrics = await testAdapter . getMetrics ( )
342+ metrics . assert ( t , { name : 'ws_subscription_active' , labels, expectedValue : 1 } )
343+ metrics . assert ( t , { name : 'ws_subscription_total' , labels, expectedValue : 1 } )
344+ metrics . assert ( t , {
345+ name : 'ws_message_total' ,
346+ labels : { ...labels , direction : 'sent' } ,
347+ expectedValue : 1 ,
348+ } )
349+
350+ // Advance to next cycle where connection is unhealthy and reconnect
351+ await runAllUntilTime ( t . context . clock , BACKGROUND_EXECUTE_MS_WS + 100 )
326352
327353 // The connection was opened twice
328354 t . is ( connectionCounter , 2 )
329355 // The subscribe message was sent twice as well, since when we reopened we resubscribed to everything
330356 t . is ( messageCounter , 2 )
331357
358+ // Only one active sub should be recorded
359+ metrics = await testAdapter . getMetrics ( )
360+ metrics . assert ( t , { name : 'ws_subscription_active' , labels, expectedValue : 1 } )
361+ metrics . assert ( t , { name : 'ws_subscription_total' , labels, expectedValue : 2 } )
362+ metrics . assert ( t , {
363+ name : 'ws_message_total' ,
364+ labels : { ...labels , direction : 'sent' } ,
365+ expectedValue : 2 ,
366+ } )
367+
368+ process . env [ 'METRICS_ENABLED' ] = 'false'
332369 testAdapter . api . close ( )
333370 mockWsServer . close ( )
334371 await t . context . clock . runToLastAsync ( )
@@ -432,6 +469,7 @@ test.serial(
432469 const base = 'ETH'
433470 const quote = 'DOGE'
434471 process . env [ 'METRICS_ENABLED' ] = 'true'
472+ eaMetrics . clear ( )
435473
436474 let execution = 0
437475
0 commit comments