mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[testUtils/esTestCluster] use more standard api style (#13197)
This commit is contained in:
parent
b678b4b46d
commit
d36080bca8
5 changed files with 81 additions and 85 deletions
|
@ -1,12 +1,12 @@
|
|||
import { format } from 'util';
|
||||
|
||||
import * as kbnTestServer from '../../../../test_utils/kbn_server';
|
||||
import { esTestCluster } from '../../../../test_utils/es';
|
||||
import { createEsTestCluster } from '../../../../test_utils/es';
|
||||
|
||||
describe('plugins/elasticsearch', function () {
|
||||
describe('routes', function () {
|
||||
let kbnServer;
|
||||
const es = esTestCluster.use({
|
||||
const es = createEsTestCluster({
|
||||
name: 'core_plugins/es/routes',
|
||||
});
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import { format as formatUrl } from 'url';
|
|||
|
||||
import { readConfigFile } from '../../lib';
|
||||
import { createToolingLog, createReduceStream } from '../../../utils';
|
||||
import { esTestCluster } from '../../../test_utils/es';
|
||||
import { createEsTestCluster } from '../../../test_utils/es';
|
||||
import { startupKibana } from '../lib';
|
||||
|
||||
const SCRIPT = resolve(__dirname, '../../../../scripts/functional_test_runner.js');
|
||||
|
@ -24,7 +24,7 @@ describe('single test that uses esArchiver', () => {
|
|||
log.info('starting elasticsearch');
|
||||
log.indent(2);
|
||||
|
||||
const es = esTestCluster.use({
|
||||
const es = createEsTestCluster({
|
||||
log: msg => log.debug(msg),
|
||||
name: 'ftr/withEsArchiver',
|
||||
port: config.get('servers.elasticsearch.port')
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import expect from 'expect.js';
|
||||
import * as kbnTestServer from '../../../test_utils/kbn_server';
|
||||
import { esTestCluster } from '../../../test_utils/es';
|
||||
import { createEsTestCluster } from '../../../test_utils/es';
|
||||
|
||||
describe('routes', () => {
|
||||
let kbnServer;
|
||||
const es = esTestCluster.use({
|
||||
const es = createEsTestCluster({
|
||||
name: 'server/http',
|
||||
});
|
||||
|
||||
|
|
|
@ -1,103 +1,99 @@
|
|||
import { resolve } from 'path';
|
||||
import { esTestConfig } from './es_test_config';
|
||||
|
||||
import libesvm from 'libesvm';
|
||||
|
||||
import { esTestConfig } from './es_test_config';
|
||||
|
||||
const ESVM_DIR = resolve(__dirname, '../../../esvm/test_utils/es_test_cluster');
|
||||
const BRANCHES_DOWNLOADED = [];
|
||||
|
||||
export class EsTestCluster {
|
||||
_branchesDownloaded = [];
|
||||
function isDownloadNeeded(branch) {
|
||||
if (process.env.ESVM_NO_FRESH || process.argv.includes('--esvm-no-fresh')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
use(options = {}) {
|
||||
const {
|
||||
name,
|
||||
log = console.log,
|
||||
port = esTestConfig.getPort(),
|
||||
branch = esTestConfig.getBranch(),
|
||||
} = options;
|
||||
if (BRANCHES_DOWNLOADED.includes(branch)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!name) {
|
||||
throw new Error('esTestCluster.use() requires { name }');
|
||||
return true;
|
||||
}
|
||||
|
||||
export function createEsTestCluster(options = {}) {
|
||||
const {
|
||||
name,
|
||||
log = console.log,
|
||||
port = esTestConfig.getPort(),
|
||||
branch = esTestConfig.getBranch(),
|
||||
} = options;
|
||||
|
||||
if (!name) {
|
||||
throw new Error('createEsTestCluster() requires { name }');
|
||||
}
|
||||
|
||||
// assigned in use.start(), reassigned in use.stop()
|
||||
let cluster;
|
||||
|
||||
return new class EsTestCluster {
|
||||
getStartTimeout() {
|
||||
return esTestConfig.getLibesvmStartTimeout();
|
||||
}
|
||||
|
||||
// assigned in use.start(), reassigned in use.stop()
|
||||
let cluster;
|
||||
async start() {
|
||||
const download = isDownloadNeeded(branch);
|
||||
|
||||
return {
|
||||
getStartTimeout: () => {
|
||||
return esTestConfig.getLibesvmStartTimeout();
|
||||
},
|
||||
if (cluster) {
|
||||
throw new Error(`
|
||||
EsTestCluster[${name}] is already started, call and await es.stop()
|
||||
before calling es.start() again.
|
||||
`);
|
||||
}
|
||||
|
||||
start: async () => {
|
||||
const download = this._isDownloadNeeded(branch);
|
||||
|
||||
if (cluster) {
|
||||
throw new Error(`
|
||||
EsTestCluster[${name}] is already started, call and await es.stop()
|
||||
before calling es.start() again.
|
||||
`);
|
||||
}
|
||||
|
||||
cluster = libesvm.createCluster({
|
||||
fresh: download,
|
||||
purge: !download,
|
||||
directory: ESVM_DIR,
|
||||
branch,
|
||||
config: {
|
||||
http: {
|
||||
port,
|
||||
},
|
||||
cluster: {
|
||||
name,
|
||||
},
|
||||
discovery: {
|
||||
zen: {
|
||||
ping: {
|
||||
unicast: {
|
||||
hosts: [ `localhost:${port}` ]
|
||||
}
|
||||
cluster = libesvm.createCluster({
|
||||
fresh: download,
|
||||
purge: !download,
|
||||
directory: ESVM_DIR,
|
||||
branch,
|
||||
config: {
|
||||
http: {
|
||||
port,
|
||||
},
|
||||
cluster: {
|
||||
name,
|
||||
},
|
||||
discovery: {
|
||||
zen: {
|
||||
ping: {
|
||||
unicast: {
|
||||
hosts: [ `localhost:${port}` ]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
cluster.on('log', (event) => {
|
||||
log(`EsTestCluster[${name}]: ${event.type} - ${event.message}`);
|
||||
});
|
||||
|
||||
await cluster.install();
|
||||
|
||||
if (download) {
|
||||
// track the branches that have successfully downloaded
|
||||
// after cluster.install() resolves
|
||||
this._branchesDownloaded.push(branch);
|
||||
}
|
||||
});
|
||||
|
||||
await cluster.start();
|
||||
},
|
||||
cluster.on('log', (event) => {
|
||||
log(`EsTestCluster[${name}]: ${event.type} - ${event.message}`);
|
||||
});
|
||||
|
||||
stop: async () => {
|
||||
if (cluster) {
|
||||
const c = cluster;
|
||||
cluster = null;
|
||||
await c.shutdown();
|
||||
}
|
||||
await cluster.install();
|
||||
|
||||
if (download) {
|
||||
// track the branches that have successfully downloaded
|
||||
// after cluster.install() resolves
|
||||
BRANCHES_DOWNLOADED.push(branch);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
_isDownloadNeeded(branch) {
|
||||
if (process.env.ESVM_NO_FRESH || process.argv.includes('--esvm-no-fresh')) {
|
||||
return false;
|
||||
await cluster.start();
|
||||
}
|
||||
|
||||
if (this._branchesDownloaded.includes(branch)) {
|
||||
return false;
|
||||
async stop() {
|
||||
if (cluster) {
|
||||
const c = cluster;
|
||||
cluster = null;
|
||||
await c.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const esTestCluster = new EsTestCluster();
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
export { esTestCluster } from './es_test_cluster';
|
||||
export { esTestConfig } from './es_test_config';
|
||||
export { createEsTestCluster } from './es_test_cluster';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue