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