Always emit request aborted event (#1534)
This commit is contained in:
committed by
GitHub
parent
a7658b2a66
commit
ee50a8e770
@ -182,6 +182,7 @@ class Transport {
|
|||||||
|
|
||||||
const makeRequest = () => {
|
const makeRequest = () => {
|
||||||
if (meta.aborted === true) {
|
if (meta.aborted === true) {
|
||||||
|
this.emit('request', new RequestAbortedError(), result)
|
||||||
return process.nextTick(callback, new RequestAbortedError(), result)
|
return process.nextTick(callback, new RequestAbortedError(), result)
|
||||||
}
|
}
|
||||||
meta.connection = this.getConnection({ requestId: meta.request.id })
|
meta.connection = this.getConnection({ requestId: meta.request.id })
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const { test } = require('tap')
|
const { test } = require('tap')
|
||||||
const { Client } = require('../../')
|
const { Client, errors } = require('../../')
|
||||||
const {
|
const {
|
||||||
connection: {
|
connection: {
|
||||||
MockConnectionTimeout,
|
MockConnectionTimeout,
|
||||||
@ -1285,3 +1285,64 @@ test('Observability events should have all the expected properties', t => {
|
|||||||
t.equal(err.message, 'The client noticed that the server is not Elasticsearch and we do not support this unknown product.')
|
t.equal(err.message, 'The client noticed that the server is not Elasticsearch and we do not support this unknown product.')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('Abort a request while running the product check', t => {
|
||||||
|
t.plan(4)
|
||||||
|
const MockConnection = buildMockConnection({
|
||||||
|
onRequest (params) {
|
||||||
|
return {
|
||||||
|
statusCode: 200,
|
||||||
|
headers: {
|
||||||
|
'x-elastic-product': 'Elasticsearch'
|
||||||
|
},
|
||||||
|
body: {
|
||||||
|
name: '1ef419078577',
|
||||||
|
cluster_name: 'docker-cluster',
|
||||||
|
cluster_uuid: 'cQ5pAMvRRTyEzObH4L5mTA',
|
||||||
|
version: {
|
||||||
|
number: '8.0.0-SNAPSHOT',
|
||||||
|
build_flavor: 'default',
|
||||||
|
build_type: 'docker',
|
||||||
|
build_hash: '5fb4c050958a6b0b6a70a6fb3e616d0e390eaac3',
|
||||||
|
build_date: '2021-07-10T01:45:02.136546168Z',
|
||||||
|
build_snapshot: true,
|
||||||
|
lucene_version: '8.9.0',
|
||||||
|
minimum_wire_compatibility_version: '7.15.0',
|
||||||
|
minimum_index_compatibility_version: '7.0.0'
|
||||||
|
},
|
||||||
|
tagline: 'You Know, for Search'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const client = new Client({
|
||||||
|
node: 'http://localhost:9200',
|
||||||
|
Connection: MockConnection
|
||||||
|
})
|
||||||
|
|
||||||
|
client.on('request', (err, event) => {
|
||||||
|
if (event.meta.request.params.path.includes('search')) {
|
||||||
|
t.ok(err instanceof errors.RequestAbortedError)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// the response event won't be executed for the search
|
||||||
|
client.on('response', (err, event) => {
|
||||||
|
t.error(err)
|
||||||
|
t.equal(event.meta.request.params.path, '/')
|
||||||
|
})
|
||||||
|
|
||||||
|
const req = client.search({
|
||||||
|
index: 'foo',
|
||||||
|
body: {
|
||||||
|
query: {
|
||||||
|
match_all: {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, (err, result) => {
|
||||||
|
t.ok(err instanceof errors.RequestAbortedError)
|
||||||
|
})
|
||||||
|
|
||||||
|
setImmediate(() => req.abort())
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user