Added debug logs in test

This commit is contained in:
delvedor
2018-12-05 11:06:57 +01:00
parent 4b2df7504e
commit 8fd49389f3
4 changed files with 17 additions and 6 deletions

View File

@ -18,13 +18,12 @@ before_install:
- wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ELASTICSEARCH_VERSION}.tar.gz - wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ELASTICSEARCH_VERSION}.tar.gz
- tar -xzf elasticsearch-${ELASTICSEARCH_VERSION}.tar.gz - tar -xzf elasticsearch-${ELASTICSEARCH_VERSION}.tar.gz
- ./elasticsearch-${ELASTICSEARCH_VERSION}/bin/elasticsearch -Enode.attr.testattr=test -Epath.repo=/tmp -Erepositories.url.allowed_urls='http://snapshot.*' &> /dev/null & - ./elasticsearch-${ELASTICSEARCH_VERSION}/bin/elasticsearch -Enode.attr.testattr=test -Epath.repo=/tmp -Erepositories.url.allowed_urls='http://snapshot.*' &> /dev/null &
- ./scripts/wait-cluster.sh
install: install:
- npm install - npm install
script: script:
- npm run lint && npm run test:unit && npm run test:integration - npm run ci
notifications: notifications:
email: email:

View File

@ -16,7 +16,7 @@
], ],
"scripts": { "scripts": {
"test": "npm run lint && npm run test:unit && npm run test:types", "test": "npm run lint && npm run test:unit && npm run test:types",
"test:unit": "tap test/unit/*.test.js -J -T", "test:unit": "tap test/unit/*.test.js -T",
"test:integration": "tap test/integration/index.js -T --harmony", "test:integration": "tap test/integration/index.js -T --harmony",
"test:types": "tsc --project ./test/types/tsconfig.json", "test:types": "tsc --project ./test/types/tsconfig.json",
"lint": "standard", "lint": "standard",

View File

@ -1,9 +1,13 @@
'use strict' 'use strict'
const debug = require('debug')('elasticsearch-test')
const workq = require('workq') const workq = require('workq')
const buildServer = require('./buildServer') const buildServer = require('./buildServer')
var id = 0
function buildCluster (opts, callback) { function buildCluster (opts, callback) {
const clusterId = id++
debug(`Booting cluster '${clusterId}'`)
if (typeof opts === 'function') { if (typeof opts === 'function') {
callback = opts callback = opts
opts = {} opts = {}
@ -39,23 +43,25 @@ function buildCluster (opts, callback) {
}, },
roles: ['master', 'data', 'ingest'] roles: ['master', 'data', 'ingest']
} }
debug(`Booted cluster node '${opts.id}' on port ${port} (cluster id: '${clusterId}')`)
done() done()
}) })
} }
function shutdown () { function shutdown () {
Object.keys(nodes).forEach(id => { debug(`Shutting down cluster '${clusterId}'`)
nodes[id].server.stop() Object.keys(nodes).forEach(kill)
})
} }
function kill (id) { function kill (id) {
debug(`Shutting down cluster node '${id}' (cluster id: '${clusterId}')`)
nodes[id].server.stop() nodes[id].server.stop()
delete nodes[id] delete nodes[id]
delete sniffResult.nodes[id] delete sniffResult.nodes[id]
} }
function spawn (id, callback) { function spawn (id, callback) {
debug(`Spawning cluster node '${id}' (cluster id: '${clusterId}')`)
q.add(bootNode, { id }) q.add(bootNode, { id })
q.add((q, done) => { q.add((q, done) => {
callback() callback()
@ -71,6 +77,7 @@ function buildCluster (opts, callback) {
} }
q.drain(done => { q.drain(done => {
debug(`Cluster '${clusterId}' booted with ${opts.numberOfNodes} nodes`)
callback(cluster) callback(cluster)
done() done()
}) })

View File

@ -1,5 +1,6 @@
'use strict' 'use strict'
const debug = require('debug')('elasticsearch-test')
const stoppable = require('stoppable') const stoppable = require('stoppable')
// allow self signed certificates for testing purposes // allow self signed certificates for testing purposes
@ -15,7 +16,10 @@ const secureOpts = {
cert: readFileSync(join(__dirname, '..', 'fixtures', 'https.cert'), 'utf8') cert: readFileSync(join(__dirname, '..', 'fixtures', 'https.cert'), 'utf8')
} }
var id = 0
function buildServer (handler, opts, cb) { function buildServer (handler, opts, cb) {
const serverId = id++
debug(`Booting server '${serverId}'`)
if (cb == null) { if (cb == null) {
cb = opts cb = opts
opts = {} opts = {}
@ -32,6 +36,7 @@ function buildServer (handler, opts, cb) {
}) })
server.listen(0, () => { server.listen(0, () => {
const port = server.address().port const port = server.address().port
debug(`Server '${serverId}' booted on port ${port}`)
cb(Object.assign({}, secureOpts, { port }), server) cb(Object.assign({}, secureOpts, { port }), server)
}) })
} }