@@ -27,17 +27,26 @@ test('Scroll search', async t => {
27
27
var count = 0
28
28
const MockConnection = connection . buildMockConnection ( {
29
29
onRequest ( params ) {
30
- t . strictEqual ( params . querystring , 'scroll=1m' )
30
+ count += 1
31
+ if ( params . method === 'POST' ) {
32
+ t . strictEqual ( params . querystring , 'scroll=1m' )
33
+ }
34
+ if ( count === 4 ) {
35
+ // final automated clear
36
+ t . strictEqual ( params . method , 'DELETE' )
37
+ }
31
38
return {
32
39
body : {
33
- _scroll_id : count === 3 ? undefined : 'id' ,
40
+ _scroll_id : 'id' ,
34
41
count,
35
42
hits : {
36
- hits : [
37
- { _source : { one : 'one' } } ,
38
- { _source : { two : 'two' } } ,
39
- { _source : { three : 'three' } }
40
- ]
43
+ hits : count === 3
44
+ ? [ ]
45
+ : [
46
+ { _source : { one : 'one' } } ,
47
+ { _source : { two : 'two' } } ,
48
+ { _source : { three : 'three' } }
49
+ ]
41
50
}
42
51
}
43
52
}
@@ -56,12 +65,7 @@ test('Scroll search', async t => {
56
65
57
66
for await ( const result of scrollSearch ) {
58
67
t . strictEqual ( result . body . count , count )
59
- if ( count < 3 ) {
60
- t . strictEqual ( result . body . _scroll_id , 'id' )
61
- } else {
62
- t . strictEqual ( result . body . _scroll_id , undefined )
63
- }
64
- count += 1
68
+ t . strictEqual ( result . body . _scroll_id , 'id' )
65
69
}
66
70
} )
67
71
@@ -115,21 +119,27 @@ test('Scroll search (retry)', async t => {
115
119
var count = 0
116
120
const MockConnection = connection . buildMockConnection ( {
117
121
onRequest ( params ) {
122
+ count += 1
118
123
if ( count === 1 ) {
119
- count += 1
120
124
return { body : { } , statusCode : 429 }
121
125
}
126
+ if ( count === 5 ) {
127
+ // final automated clear
128
+ t . strictEqual ( params . method , 'DELETE' )
129
+ }
122
130
return {
123
131
statusCode : 200 ,
124
132
body : {
125
- _scroll_id : count === 4 ? undefined : 'id' ,
133
+ _scroll_id : 'id' ,
126
134
count,
127
135
hits : {
128
- hits : [
129
- { _source : { one : 'one' } } ,
130
- { _source : { two : 'two' } } ,
131
- { _source : { three : 'three' } }
132
- ]
136
+ hits : count === 4
137
+ ? [ ]
138
+ : [
139
+ { _source : { one : 'one' } } ,
140
+ { _source : { two : 'two' } } ,
141
+ { _source : { three : 'three' } }
142
+ ]
133
143
}
134
144
}
135
145
}
@@ -151,12 +161,7 @@ test('Scroll search (retry)', async t => {
151
161
for await ( const result of scrollSearch ) {
152
162
t . strictEqual ( result . body . count , count )
153
163
t . notStrictEqual ( result . body . count , 1 )
154
- if ( count < 4 ) {
155
- t . strictEqual ( result . body . _scroll_id , 'id' )
156
- } else {
157
- t . strictEqual ( result . body . _scroll_id , undefined )
158
- }
159
- count += 1
164
+ t . strictEqual ( result . body . _scroll_id , 'id' )
160
165
}
161
166
} )
162
167
@@ -198,20 +203,20 @@ test('Scroll search (retry throws and maxRetries)', async t => {
198
203
199
204
test ( 'Scroll search (retry throws later)' , async t => {
200
205
const maxRetries = 5
201
- const expectedAttempts = maxRetries + 1
206
+ const expectedAttempts = maxRetries + 2
202
207
var count = 0
203
208
const MockConnection = connection . buildMockConnection ( {
204
209
onRequest ( params ) {
205
- // filter_path should not be added if is not already present
210
+ count += 1
211
+ // filter_path should not be added if is not already present
206
212
t . strictEqual ( params . querystring , 'scroll=1m' )
207
213
if ( count > 1 ) {
208
- count += 1
209
214
return { body : { } , statusCode : 429 }
210
215
}
211
216
return {
212
217
statusCode : 200 ,
213
218
body : {
214
- _scroll_id : count === 4 ? undefined : 'id' ,
219
+ _scroll_id : 'id' ,
215
220
count,
216
221
hits : {
217
222
hits : [
@@ -227,7 +232,8 @@ test('Scroll search (retry throws later)', async t => {
227
232
228
233
const client = new Client ( {
229
234
node : 'http://localhost:9200' ,
230
- Connection : MockConnection
235
+ Connection : MockConnection ,
236
+ maxRetries
231
237
} )
232
238
233
239
const scrollSearch = client . helpers . scrollSearch ( {
@@ -240,7 +246,6 @@ test('Scroll search (retry throws later)', async t => {
240
246
try {
241
247
for await ( const result of scrollSearch ) { // eslint-disable-line
242
248
t . strictEqual ( result . body . count , count )
243
- count += 1
244
249
}
245
250
} catch ( err ) {
246
251
t . true ( err instanceof errors . ResponseError )
@@ -256,19 +261,23 @@ test('Scroll search documents', async t => {
256
261
if ( count === 0 ) {
257
262
t . strictEqual ( params . querystring , 'filter_path=hits.hits._source%2C_scroll_id&scroll=1m' )
258
263
} else {
259
- t . strictEqual ( params . querystring , 'scroll=1m' )
260
- t . strictEqual ( params . body , '{"scroll_id":"id"}' )
264
+ if ( params . method !== 'DELETE' ) {
265
+ t . strictEqual ( params . querystring , 'scroll=1m' )
266
+ t . strictEqual ( params . body , '{"scroll_id":"id"}' )
267
+ }
261
268
}
262
269
return {
263
270
body : {
264
- _scroll_id : count === 3 ? undefined : 'id' ,
271
+ _scroll_id : 'id' ,
265
272
count,
266
273
hits : {
267
- hits : [
268
- { _source : { val : 1 * count } } ,
269
- { _source : { val : 2 * count } } ,
270
- { _source : { val : 3 * count } }
271
- ]
274
+ hits : count === 3
275
+ ? [ ]
276
+ : [
277
+ { _source : { val : 1 * count } } ,
278
+ { _source : { val : 2 * count } } ,
279
+ { _source : { val : 3 * count } }
280
+ ]
272
281
}
273
282
}
274
283
}
@@ -339,15 +348,19 @@ test('Fix querystring for scroll search', async t => {
339
348
if ( count === 0 ) {
340
349
t . strictEqual ( params . querystring , 'size=1&scroll=1m' )
341
350
} else {
342
- t . strictEqual ( params . querystring , 'scroll=1m' )
351
+ if ( params . method !== 'DELETE' ) {
352
+ t . strictEqual ( params . querystring , 'scroll=1m' )
353
+ }
343
354
}
344
355
return {
345
356
body : {
346
- _scroll_id : count === 3 ? undefined : 'id' ,
357
+ _scroll_id : 'id' ,
347
358
hits : {
348
- hits : [
349
- { _source : { val : count } }
350
- ]
359
+ hits : count === 3
360
+ ? [ ]
361
+ : [
362
+ { _source : { val : count } }
363
+ ]
351
364
}
352
365
}
353
366
}
0 commit comments