Updated test
This commit is contained in:
125
test/benchmarks/basic.bench.js
Normal file
125
test/benchmarks/basic.bench.js
Normal file
@ -0,0 +1,125 @@
|
||||
'use strict'
|
||||
|
||||
const bench = require('nanobench')
|
||||
const { Client } = require('../../index')
|
||||
const { connection } = require('../utils')
|
||||
|
||||
bench('Initialization', { repetitions: 5 }, b => {
|
||||
const client = new Client({ // eslint-disable-line
|
||||
node: 'http://localhost:9200'
|
||||
})
|
||||
b.end()
|
||||
})
|
||||
|
||||
bench('Call api with lazy loading', { repetitions: 5 }, b => {
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
Connection: connection.MockConnection
|
||||
})
|
||||
|
||||
b.start()
|
||||
client.info((err, result) => {
|
||||
if (err) {
|
||||
b.error(err)
|
||||
return
|
||||
}
|
||||
|
||||
b.end()
|
||||
})
|
||||
})
|
||||
|
||||
bench('Call api without lazy loading', { repetitions: 5 }, b => {
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
Connection: connection.MockConnection
|
||||
})
|
||||
|
||||
client.info((err, result) => {
|
||||
if (err) {
|
||||
b.error(err)
|
||||
return
|
||||
}
|
||||
|
||||
b.start()
|
||||
client.info((err, result) => {
|
||||
if (err) {
|
||||
b.error(err)
|
||||
return
|
||||
}
|
||||
|
||||
b.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
bench('Basic get', { repetitions: 5 }, b => {
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
Connection: connection.MockConnection
|
||||
})
|
||||
|
||||
// we run the method twice to skip the lazy loading overhead
|
||||
client.search({
|
||||
index: 'test',
|
||||
type: 'doc',
|
||||
q: 'foo:bar'
|
||||
}, (err, result) => {
|
||||
if (err) {
|
||||
b.error(err)
|
||||
return
|
||||
}
|
||||
|
||||
b.start()
|
||||
client.search({
|
||||
index: 'test',
|
||||
type: 'doc',
|
||||
q: 'foo:bar'
|
||||
}, (err, result) => {
|
||||
if (err) {
|
||||
b.error(err)
|
||||
return
|
||||
}
|
||||
b.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
bench('Basic post', { repetitions: 5 }, b => {
|
||||
const client = new Client({
|
||||
node: 'http://localhost:9200',
|
||||
Connection: connection.MockConnection
|
||||
})
|
||||
|
||||
// we run the method twice to skip the lazy loading overhead
|
||||
client.search({
|
||||
index: 'test',
|
||||
type: 'doc',
|
||||
body: {
|
||||
query: {
|
||||
match: { foo: 'bar' }
|
||||
}
|
||||
}
|
||||
}, (err, result) => {
|
||||
if (err) {
|
||||
b.error(err)
|
||||
return
|
||||
}
|
||||
|
||||
b.start()
|
||||
client.search({
|
||||
index: 'test',
|
||||
type: 'doc',
|
||||
body: {
|
||||
query: {
|
||||
match: { foo: 'bar' }
|
||||
}
|
||||
}
|
||||
}, (err, result) => {
|
||||
if (err) {
|
||||
b.error(err)
|
||||
return
|
||||
}
|
||||
b.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -88,6 +88,21 @@ test('qserialize (string)', t => {
|
||||
)
|
||||
})
|
||||
|
||||
test('qserialize (key with undefined value)', t => {
|
||||
t.plan(1)
|
||||
const s = new Serializer()
|
||||
const obj = {
|
||||
hello: 'world',
|
||||
key: undefined,
|
||||
foo: 'bar'
|
||||
}
|
||||
|
||||
t.strictEqual(
|
||||
s.qserialize(obj),
|
||||
'hello=world&foo=bar'
|
||||
)
|
||||
})
|
||||
|
||||
test('SerializationError', t => {
|
||||
t.plan(1)
|
||||
const s = new Serializer()
|
||||
|
||||
@ -53,6 +53,62 @@ test('Basic', t => {
|
||||
})
|
||||
})
|
||||
|
||||
test('Basic (promises support)', t => {
|
||||
t.plan(1)
|
||||
|
||||
const pool = new ConnectionPool({ Connection: MockConnection })
|
||||
pool.addConnection('http://localhost:9200')
|
||||
|
||||
const transport = new Transport({
|
||||
emit: () => {},
|
||||
connectionPool: pool,
|
||||
serializer: new Serializer(),
|
||||
maxRetries: 3,
|
||||
requestTimeout: 30000,
|
||||
sniffInterval: false,
|
||||
sniffOnStart: false
|
||||
})
|
||||
|
||||
transport
|
||||
.request({
|
||||
method: 'GET',
|
||||
path: '/hello'
|
||||
})
|
||||
.then(({ body }) => {
|
||||
t.deepEqual(body, { hello: 'world' })
|
||||
})
|
||||
.catch(t.fail)
|
||||
})
|
||||
|
||||
test('Basic (options + promises support)', t => {
|
||||
t.plan(1)
|
||||
|
||||
const pool = new ConnectionPool({ Connection: MockConnection })
|
||||
pool.addConnection('http://localhost:9200')
|
||||
|
||||
const transport = new Transport({
|
||||
emit: () => {},
|
||||
connectionPool: pool,
|
||||
serializer: new Serializer(),
|
||||
maxRetries: 3,
|
||||
requestTimeout: 30000,
|
||||
sniffInterval: false,
|
||||
sniffOnStart: false
|
||||
})
|
||||
|
||||
transport
|
||||
.request({
|
||||
method: 'GET',
|
||||
path: '/hello'
|
||||
}, {
|
||||
requestTimeout: 1000
|
||||
})
|
||||
.then(({ body }) => {
|
||||
t.deepEqual(body, { hello: 'world' })
|
||||
})
|
||||
.catch(t.fail)
|
||||
})
|
||||
|
||||
test('Send POST', t => {
|
||||
t.plan(4)
|
||||
function handler (req, res) {
|
||||
|
||||
Reference in New Issue
Block a user