|
20 | 20 | 'use strict'
|
21 | 21 |
|
22 | 22 | const { test } = require('tap')
|
23 |
| -const { Client } = require('../../') |
| 23 | +const { Client, errors } = require('../../') |
24 | 24 | const {
|
25 | 25 | connection: {
|
26 | 26 | MockConnectionTimeout,
|
@@ -1285,3 +1285,64 @@ test('Observability events should have all the expected properties', t => {
|
1285 | 1285 | t.equal(err.message, 'The client noticed that the server is not Elasticsearch and we do not support this unknown product.')
|
1286 | 1286 | })
|
1287 | 1287 | })
|
| 1288 | + |
| 1289 | +test('Abort a request while running the product check', t => { |
| 1290 | + t.plan(4) |
| 1291 | + const MockConnection = buildMockConnection({ |
| 1292 | + onRequest (params) { |
| 1293 | + return { |
| 1294 | + statusCode: 200, |
| 1295 | + headers: { |
| 1296 | + 'x-elastic-product': 'Elasticsearch' |
| 1297 | + }, |
| 1298 | + body: { |
| 1299 | + name: '1ef419078577', |
| 1300 | + cluster_name: 'docker-cluster', |
| 1301 | + cluster_uuid: 'cQ5pAMvRRTyEzObH4L5mTA', |
| 1302 | + version: { |
| 1303 | + number: '8.0.0-SNAPSHOT', |
| 1304 | + build_flavor: 'default', |
| 1305 | + build_type: 'docker', |
| 1306 | + build_hash: '5fb4c050958a6b0b6a70a6fb3e616d0e390eaac3', |
| 1307 | + build_date: '2021-07-10T01:45:02.136546168Z', |
| 1308 | + build_snapshot: true, |
| 1309 | + lucene_version: '8.9.0', |
| 1310 | + minimum_wire_compatibility_version: '7.15.0', |
| 1311 | + minimum_index_compatibility_version: '7.0.0' |
| 1312 | + }, |
| 1313 | + tagline: 'You Know, for Search' |
| 1314 | + } |
| 1315 | + } |
| 1316 | + } |
| 1317 | + }) |
| 1318 | + |
| 1319 | + const client = new Client({ |
| 1320 | + node: 'http://localhost:9200', |
| 1321 | + Connection: MockConnection |
| 1322 | + }) |
| 1323 | + |
| 1324 | + client.on('request', (err, event) => { |
| 1325 | + if (event.meta.request.params.path.includes('search')) { |
| 1326 | + t.ok(err instanceof errors.RequestAbortedError) |
| 1327 | + } |
| 1328 | + }) |
| 1329 | + |
| 1330 | + // the response event won't be executed for the search |
| 1331 | + client.on('response', (err, event) => { |
| 1332 | + t.error(err) |
| 1333 | + t.equal(event.meta.request.params.path, '/') |
| 1334 | + }) |
| 1335 | + |
| 1336 | + const req = client.search({ |
| 1337 | + index: 'foo', |
| 1338 | + body: { |
| 1339 | + query: { |
| 1340 | + match_all: {} |
| 1341 | + } |
| 1342 | + } |
| 1343 | + }, (err, result) => { |
| 1344 | + t.ok(err instanceof errors.RequestAbortedError) |
| 1345 | + }) |
| 1346 | + |
| 1347 | + setImmediate(() => req.abort()) |
| 1348 | +}) |
0 commit comments