1+ import  assert  from  "node:assert/strict" ; 
2+ import  testUtils ,  {  GLOBAL  }  from  "../test-utils" ; 
3+ import  LATENCY_HISTOGRAM  from  "./LATENCY_HISTOGRAM" ; 
4+ import  {  parseArgs  }  from  "./generic-transformers" ; 
5+ 
6+ describe ( "LATENCY HISTOGRAM" ,  ( )  =>  { 
7+  describe ( "transformArguments" ,  ( )  =>  { 
8+  it ( "filtered by command set" ,  ( )  =>  { 
9+  assert . deepEqual ( parseArgs ( LATENCY_HISTOGRAM ,  "set" ) ,  [ 
10+  "LATENCY" , 
11+  "HISTOGRAM" , 
12+  "set" , 
13+  ] ) ; 
14+  } ) ; 
15+ 
16+  it ( "unfiltered" ,  ( )  =>  { 
17+  assert . deepEqual ( parseArgs ( LATENCY_HISTOGRAM ) ,  [ 
18+  "LATENCY" , 
19+  "HISTOGRAM" , 
20+  ] ) ; 
21+  } ) ; 
22+  } ) ; 
23+ 
24+  describe ( "RESP 2" ,  ( )  =>  { 
25+  testUtils . testWithClient ( 
26+  "unfiltered list" , 
27+  async  ( client )  =>  { 
28+  await  client . configResetStat ( ) ; 
29+  await  Promise . all ( [ 
30+  client . lPush ( "push-key" ,  "hello " ) , 
31+  client . set ( "set-key" ,  "world!" ) , 
32+  ] ) ; 
33+  const  histogram  =  await  client . latencyHistogram ( ) ; 
34+  const  commands  =  [ "config|resetstat" ,  "set" ,  "lpush" ] ; 
35+  for  ( const  command  of  commands )  { 
36+  assert . ok ( typeof  histogram [ command ] [ "calls" ] ,  "number" ) ; 
37+  } 
38+  } , 
39+  GLOBAL . SERVERS . OPEN , 
40+  ) ; 
41+ 
42+  testUtils . testWithClient ( 
43+  "filtered by a command list" , 
44+  async  ( client )  =>  { 
45+  await  client . configSet ( "latency-monitor-threshold" ,  "100" ) ; 
46+  await  client . set ( "set-key" ,  "hello" ) ; 
47+  const  histogram  =  await  client . latencyHistogram ( "set" ) ; 
48+  assert . ok ( typeof  histogram . set [ "calls" ] ,  "number" ) ; 
49+  } , 
50+  GLOBAL . SERVERS . OPEN , 
51+  ) ; 
52+  } ) ; 
53+ 
54+  describe ( "RESP 3" ,  ( )  =>  { 
55+  testUtils . testWithClient ( 
56+  "unfiltered list" , 
57+  async  ( client )  =>  { 
58+  await  client . configResetStat ( ) ; 
59+  await  Promise . all ( [ 
60+  client . lPush ( "push-key" ,  "hello " ) , 
61+  client . set ( "set-key" ,  "world!" ) , 
62+  ] ) ; 
63+  const  histogram  =  await  client . latencyHistogram ( ) ; 
64+  const  commands  =  [ "config|resetstat" ,  "set" ,  "lpush" ] ; 
65+  for  ( const  command  of  commands )  { 
66+  assert . ok ( typeof  histogram [ command ] [ "calls" ] ,  "number" ) ; 
67+  } 
68+  } , 
69+  { 
70+  ...GLOBAL . SERVERS . OPEN , 
71+  clientOptions : { 
72+  RESP : 3 , 
73+  } , 
74+  } , 
75+  ) ; 
76+ 
77+  testUtils . testWithClient ( 
78+  "filtered by a command list" , 
79+  async  ( client )  =>  { 
80+  await  client . configSet ( "latency-monitor-threshold" ,  "100" ) ; 
81+  await  client . set ( "set-key" ,  "hello" ) ; 
82+  const  histogram  =  await  client . latencyHistogram ( "set" ) ; 
83+  assert . ok ( typeof  histogram . set [ "calls" ] ,  "number" ) ; 
84+  } , 
85+  { 
86+  ...GLOBAL . SERVERS . OPEN , 
87+  clientOptions : { 
88+  RESP : 3 , 
89+  } , 
90+  } , 
91+  ) ; 
92+  } ) ; 
93+ } ) ; 
0 commit comments