Improve child performances (#1314)

This commit is contained in:
Tomas Della Vedova
2020-09-23 11:31:09 +02:00
committed by GitHub
parent 19f570f067
commit a064f0f357
400 changed files with 15119 additions and 38598 deletions

View File

@ -0,0 +1,7 @@
'use strict'
const { Client } = require('../../../index')
const client = new Client({ node: 'http://localhost:9200' })
client.info((err, result) => {
process.exit(err ? 1 : 0)
})

View File

@ -0,0 +1,16 @@
{
"name": "parcel-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node bundle.js",
"build": "parcel build index.js --target node --bundle-node-modules --out-file bundle.js --no-source-maps --out-dir ."
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"parcel-bundler": "^1.12.4"
}
}

View File

@ -0,0 +1,7 @@
'use strict'
const { Client } = require('../../../index')
const client = new Client({ node: 'http://localhost:9200' })
client.info((err, result) => {
process.exit(err ? 1 : 0)
})

View File

@ -0,0 +1,19 @@
{
"name": "rollup-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node bundle.js",
"build": "rollup -c"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"rollup": "^2.28.0"
}
}

View File

@ -0,0 +1,13 @@
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
export default {
input: 'index.js',
output: {
file: 'bundle.js',
format: 'iife',
name: 'MyModule'
},
plugins: [resolve(), commonjs({ include: ['../../../node_modules/**'] }), json()]
}

View File

@ -0,0 +1,7 @@
'use strict'
const { Client } = require('../../../index')
const client = new Client({ node: 'http://localhost:9200' })
client.info((err, result) => {
process.exit(err ? 1 : 0)
})

View File

@ -0,0 +1,17 @@
{
"name": "webpack-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node bundle.js",
"build": "webpack"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"webpack": "^4.44.2",
"webpack-cli": "^3.3.12"
}
}

View File

@ -0,0 +1,12 @@
'use strict'
const path = require('path')
module.exports = {
entry: './index.js',
target: 'node',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname)
}
}

View File

@ -60,7 +60,7 @@ function build (opts = {}) {
await client.indices.deleteAlias({
index: '_all',
name: '_all'
}, { ignore: 404 })
}, { ignore: [404] })
} catch (err) {
assert.ifError(err, 'should not error: indices.deleteAlias')
}
@ -69,7 +69,7 @@ function build (opts = {}) {
await client.indices.delete({
index: '_all',
expand_wildcards: 'open,closed,hidden'
}, { ignore: 404 })
}, { ignore: [404] })
} catch (err) {
assert.ifError(err, 'should not error: indices.delete')
}
@ -392,6 +392,7 @@ function build (opts = {}) {
}
const options = { ignore: cmd.params.ignore, headers: action.headers }
if (!Array.isArray(options.ignore)) options.ignore = [options.ignore]
if (cmd.params.ignore) delete cmd.params.ignore
const [err, result] = await to(api(cmd.params, options))

View File

@ -233,33 +233,6 @@ test('Basic (options and promises)', t => {
})
})
test('Pass unknown parameters as query parameters (and get a warning)', t => {
t.plan(4)
function handler (req, res) {
t.strictEqual(req.url, '/test/_search?q=foo%3Abar&winter=is%20coming')
res.setHeader('Content-Type', 'application/json;utf=8')
res.end(JSON.stringify({ hello: 'world' }))
}
buildServer(handler, ({ port }, server) => {
const client = new Client({
node: `http://localhost:${port}`
})
client.search({
index: 'test',
q: 'foo:bar',
winter: 'is coming'
}, (err, { body, warnings }) => {
t.error(err)
t.deepEqual(body, { hello: 'world' })
t.deepEqual(warnings, ['Client - Unknown parameter: "winter", sending it as query parameter'])
server.stop()
})
})
})
test('If the API uses the same key for both url and query parameter, the url should win', t => {
t.plan(2)

View File

@ -280,3 +280,41 @@ test('Should create a child client (name check)', t => {
child.info(t.error)
})
})
test('Should create a child client (auth check)', t => {
t.plan(4)
var count = 0
function handler (req, res) {
if (count++ === 0) {
t.match(req.headers, { authorization: 'Basic Zm9vOmJhcg==' })
} else {
t.match(req.headers, { authorization: 'ApiKey foobar' })
}
res.setHeader('Content-Type', 'application/json;utf=8')
res.end(JSON.stringify({ hello: 'world' }))
}
buildServer(handler, ({ port }, server) => {
const client = new Client({
node: `http://localhost:${port}`,
auth: {
username: 'foo',
password: 'bar'
}
})
const child = client.child({
auth: {
apiKey: 'foobar'
}
})
client.info((err, res) => {
t.error(err)
child.info((err, res) => {
t.error(err)
server.stop()
})
})
})
})

View File

@ -1806,45 +1806,6 @@ test('Warning header', t => {
})
})
t.test('Multiple warnings and external warning', t => {
t.plan(5)
const warn1 = '112 - "cache down" "Wed, 21 Oct 2015 07:28:00 GMT"'
const warn2 = '199 agent "Error message" "2015-01-01"'
function handler (req, res) {
res.setHeader('Content-Type', 'application/json;utf=8')
res.setHeader('Warning', warn1 + ',' + warn2)
res.end(JSON.stringify({ hello: 'world' }))
}
buildServer(handler, ({ port }, server) => {
const pool = new ConnectionPool({ Connection })
pool.addConnection(`http://localhost:${port}`)
const transport = new Transport({
emit: () => {},
connectionPool: pool,
serializer: new Serializer(),
maxRetries: 3,
requestTimeout: 30000,
sniffInterval: false,
sniffOnStart: false
})
transport.request({
method: 'GET',
path: '/hello'
}, {
warnings: ['winter is coming']
}, (err, { warnings }) => {
t.error(err)
t.deepEqual(warnings, ['winter is coming', warn1, warn2])
warnings.forEach(w => t.type(w, 'string'))
server.stop()
})
})
})
t.end()
})