@@ -7,43 +7,106 @@ import { parseArgs } from '@redis/client/lib/commands/generic-transformers';
77import { DEFAULT_DIALECT } from '../dialect/default' ;
88
99describe ( 'PROFILE AGGREGATE' , ( ) => {
10- describe ( 'transformArguments' , ( ) => {
11- it ( 'without options' , ( ) => {
12- assert . deepEqual (
13- parseArgs ( PROFILE_AGGREGATE , 'index' , 'query' ) ,
14- [ 'FT.PROFILE' , 'index' , 'AGGREGATE' , 'QUERY' , 'query' , 'DIALECT' , DEFAULT_DIALECT ]
15- ) ;
16- } ) ;
17-
18- it ( 'with options' , ( ) => {
19- assert . deepEqual (
20- parseArgs ( PROFILE_AGGREGATE , 'index' , 'query' , {
21- LIMITED : true ,
22- VERBATIM : true ,
23- STEPS : [ {
24- type : FT_AGGREGATE_STEPS . SORTBY ,
25- BY : '@by'
26- } ]
27- } ) ,
28- [ 'FT.PROFILE' , 'index' , 'AGGREGATE' , 'LIMITED' , 'QUERY' , 'query' ,
29- 'VERBATIM' , 'SORTBY' , '1' , '@by' , 'DIALECT' , DEFAULT_DIALECT ]
30- ) ;
31- } ) ;
10+ describe ( 'transformArguments' , ( ) => {
11+ it ( 'without options' , ( ) => {
12+ assert . deepEqual (
13+ parseArgs ( PROFILE_AGGREGATE , 'index' , 'query' ) ,
14+ [ 'FT.PROFILE' , 'index' , 'AGGREGATE' , 'QUERY' , 'query' , 'DIALECT' , DEFAULT_DIALECT ]
15+ ) ;
3216 } ) ;
3317
34- testUtils . testWithClient ( 'client.ft.search' , async client => {
35- await Promise . all ( [
36- client . ft . create ( 'index' , {
37- field : SCHEMA_FIELD_TYPE . NUMERIC
38- } ) ,
39- client . hSet ( '1' , 'field' , '1' ) ,
40- client . hSet ( '2' , 'field' , '2' )
41- ] ) ;
42-
43- const res = await client . ft . profileAggregate ( 'index' , '*' ) ;
44- assert . deepEqual ( 'None' , res . profile . warning ) ;
45- assert . ok ( typeof res . profile . iteratorsProfile . counter === 'number' ) ;
46- assert . ok ( typeof res . profile . parsingTime === 'string' ) ;
47- assert . ok ( res . results . total == 1 ) ;
48- } , GLOBAL . SERVERS . OPEN ) ;
18+ it ( 'with options' , ( ) => {
19+ assert . deepEqual (
20+ parseArgs ( PROFILE_AGGREGATE , 'index' , 'query' , {
21+ LIMITED : true ,
22+ VERBATIM : true ,
23+ STEPS : [ {
24+ type : FT_AGGREGATE_STEPS . SORTBY ,
25+ BY : '@by'
26+ } ]
27+ } ) ,
28+ [ 'FT.PROFILE' , 'index' , 'AGGREGATE' , 'LIMITED' , 'QUERY' , 'query' ,
29+ 'VERBATIM' , 'SORTBY' , '1' , '@by' , 'DIALECT' , DEFAULT_DIALECT ]
30+ ) ;
31+ } ) ;
32+ } ) ;
33+
34+ testUtils . testWithClientIfVersionWithinRange ( [ [ 8 ] , 'LATEST' ] , 'client.ft.search' , async client => {
35+ await Promise . all ( [
36+ client . ft . create ( 'index' , {
37+ field : SCHEMA_FIELD_TYPE . NUMERIC
38+ } ) ,
39+ client . hSet ( '1' , 'field' , '1' ) ,
40+ client . hSet ( '2' , 'field' , '2' )
41+ ] ) ;
42+
43+
44+ const normalizeObject = obj => JSON . parse ( JSON . stringify ( obj ) ) ;
45+ const res = await client . ft . profileAggregate ( 'index' , '*' ) ;
46+
47+ const normalizedRes = normalizeObject ( res ) ;
48+ assert . equal ( normalizedRes . results . total , 1 ) ;
49+
50+ assert . ok ( normalizedRes . profile [ 0 ] === 'Shards' ) ;
51+ assert . ok ( Array . isArray ( normalizedRes . profile [ 1 ] ) ) ;
52+ assert . ok ( normalizedRes . profile [ 2 ] === 'Coordinator' ) ;
53+ assert . ok ( Array . isArray ( normalizedRes . profile [ 3 ] ) ) ;
54+
55+ const shardProfile = normalizedRes . profile [ 1 ] [ 0 ] ;
56+ assert . ok ( shardProfile . includes ( 'Total profile time' ) ) ;
57+ assert . ok ( shardProfile . includes ( 'Parsing time' ) ) ;
58+ assert . ok ( shardProfile . includes ( 'Pipeline creation time' ) ) ;
59+ assert . ok ( shardProfile . includes ( 'Warning' ) ) ;
60+ assert . ok ( shardProfile . includes ( 'Iterators profile' ) ) ;
61+
62+ } , GLOBAL . SERVERS . OPEN ) ;
63+
64+ testUtils . testWithClientIfVersionWithinRange ( [ [ 7 , 2 , 0 ] , [ 7 , 4 , 0 ] ] , 'client.ft.search' , async client => {
65+ await Promise . all ( [
66+ client . ft . create ( 'index' , {
67+ field : SCHEMA_FIELD_TYPE . NUMERIC
68+ } ) ,
69+ client . hSet ( '1' , 'field' , '1' ) ,
70+ client . hSet ( '2' , 'field' , '2' )
71+ ] ) ;
72+
73+ const normalizeObject = obj => JSON . parse ( JSON . stringify ( obj ) ) ;
74+ const res = await client . ft . profileAggregate ( 'index' , '*' ) ;
75+ const normalizedRes = normalizeObject ( res ) ;
76+ assert . equal ( normalizedRes . results . total , 1 ) ;
77+
78+ assert . ok ( Array . isArray ( normalizedRes . profile ) ) ;
79+ assert . equal ( normalizedRes . profile [ 0 ] [ 0 ] , 'Total profile time' ) ;
80+ assert . equal ( normalizedRes . profile [ 1 ] [ 0 ] , 'Parsing time' ) ;
81+ assert . equal ( normalizedRes . profile [ 2 ] [ 0 ] , 'Pipeline creation time' ) ;
82+ assert . equal ( normalizedRes . profile [ 3 ] [ 0 ] , 'Warning' ) ;
83+ assert . equal ( normalizedRes . profile [ 4 ] [ 0 ] , 'Iterators profile' ) ;
84+ assert . equal ( normalizedRes . profile [ 5 ] [ 0 ] , 'Result processors profile' ) ;
85+
86+ const iteratorsProfile = normalizedRes . profile [ 4 ] [ 1 ] ;
87+ assert . equal ( iteratorsProfile [ 0 ] , 'Type' ) ;
88+ assert . equal ( iteratorsProfile [ 1 ] , 'WILDCARD' ) ;
89+ assert . equal ( iteratorsProfile [ 2 ] , 'Time' ) ;
90+ assert . equal ( iteratorsProfile [ 4 ] , 'Counter' ) ;
91+ } , GLOBAL . SERVERS . OPEN ) ;
92+
93+ testUtils . testWithClientIfVersionWithinRange ( [ [ 8 ] , 'LATEST' ] , '[RESP3] client.ft.search' , async client => {
94+ await Promise . all ( [
95+ client . ft . create ( 'index' , {
96+ field : SCHEMA_FIELD_TYPE . NUMERIC
97+ } ) ,
98+ client . hSet ( '1' , 'field' , '1' ) ,
99+ client . hSet ( '2' , 'field' , '2' )
100+ ] ) ;
101+
102+
103+ const normalizeObject = obj => JSON . parse ( JSON . stringify ( obj ) ) ;
104+ const res = await client . ft . profileAggregate ( 'index' , '*' ) ;
105+
106+ const normalizedRes = normalizeObject ( res ) ;
107+ assert . equal ( normalizedRes . Results . total_results , 1 ) ;
108+ assert . ok ( normalizedRes . Profile . Shards ) ;
109+
110+ } , GLOBAL . SERVERS . OPEN_3 )
111+
49112} ) ;
0 commit comments