diff --git a/packages/kbn-test/src/ci_parallel_process_prefix.ts b/packages/kbn-test/src/ci_parallel_process_prefix.ts new file mode 100644 index 000000000000..67dafc7e8532 --- /dev/null +++ b/packages/kbn-test/src/ci_parallel_process_prefix.ts @@ -0,0 +1,30 @@ +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +const job = process.env.JOB ? `job-${process.env.JOB}-` : ''; +const num = process.env.CI_PARALLEL_PROCESS_NUMBER + ? `worker-${process.env.CI_PARALLEL_PROCESS_NUMBER}-` + : ''; + +/** + * A prefix string that is unique for each parallel CI process that + * is an empty string outside of CI, so it can be safely injected + * into strings as a prefix + */ +export const CI_PARALLEL_PROCESS_PREFIX = `${job}${num}`; diff --git a/packages/kbn-test/src/functional_tests/lib/run_elasticsearch.js b/packages/kbn-test/src/functional_tests/lib/run_elasticsearch.js index 136704a639bf..5f58190078f0 100644 --- a/packages/kbn-test/src/functional_tests/lib/run_elasticsearch.js +++ b/packages/kbn-test/src/functional_tests/lib/run_elasticsearch.js @@ -42,10 +42,11 @@ export async function runElasticsearch({ config, options }) { esFrom: esFrom || config.get('esTestCluster.from'), dataArchive: config.get('esTestCluster.dataArchive'), esArgs, + esEnvVars, ssl, }); - await cluster.start(esArgs, esEnvVars); + await cluster.start(); if (isSecurityEnabled) { await setupUsers({ diff --git a/packages/kbn-test/src/junit_report_path.ts b/packages/kbn-test/src/junit_report_path.ts index d46c9455dcff..90405d7a89c0 100644 --- a/packages/kbn-test/src/junit_report_path.ts +++ b/packages/kbn-test/src/junit_report_path.ts @@ -18,17 +18,13 @@ */ import { resolve } from 'path'; - -const job = process.env.JOB ? `job-${process.env.JOB}-` : ''; -const num = process.env.CI_PARALLEL_PROCESS_NUMBER - ? `worker-${process.env.CI_PARALLEL_PROCESS_NUMBER}-` - : ''; +import { CI_PARALLEL_PROCESS_PREFIX } from './ci_parallel_process_prefix'; export function makeJunitReportPath(rootDirectory: string, reportName: string) { return resolve( rootDirectory, 'target/junit', process.env.JOB || '.', - `TEST-${job}${num}${reportName}.xml` + `TEST-${CI_PARALLEL_PROCESS_PREFIX}${reportName}.xml` ); } diff --git a/packages/kbn-test/src/legacy_es/legacy_es_test_cluster.js b/packages/kbn-test/src/legacy_es/legacy_es_test_cluster.js index 355304c86a3c..f795b32d78b8 100644 --- a/packages/kbn-test/src/legacy_es/legacy_es_test_cluster.js +++ b/packages/kbn-test/src/legacy_es/legacy_es_test_cluster.js @@ -22,6 +22,7 @@ import { format } from 'url'; import { get } from 'lodash'; import toPath from 'lodash/internal/toPath'; import { Cluster } from '@kbn/es'; +import { CI_PARALLEL_PROCESS_PREFIX } from '../ci_parallel_process_prefix'; import { esTestConfig } from './es_test_config'; import { KIBANA_ROOT } from '../'; @@ -38,14 +39,22 @@ export function createLegacyEsTestCluster(options = {}) { basePath = resolve(KIBANA_ROOT, '.es'), esFrom = esTestConfig.getBuildFrom(), dataArchive, - esArgs, + esArgs: customEsArgs = [], + esEnvVars, + clusterName: customClusterName = 'es-test-cluster', ssl, } = options; - const randomHash = Math.random() - .toString(36) - .substring(2); - const clusterName = `test-${randomHash}`; + const clusterName = `${CI_PARALLEL_PROCESS_PREFIX}${customClusterName}`; + + const esArgs = [ + `cluster.name=${clusterName}`, + `http.port=${port}`, + 'discovery.type=single-node', + `transport.port=${esTestConfig.getTransportPort()}`, + ...customEsArgs, + ]; + const config = { version: esTestConfig.getVersion(), installPath: resolve(basePath, clusterName), @@ -55,7 +64,6 @@ export function createLegacyEsTestCluster(options = {}) { basePath, esArgs, }; - const transportPort = esTestConfig.getTransportPort(); const cluster = new Cluster({ log, ssl }); @@ -67,7 +75,7 @@ export function createLegacyEsTestCluster(options = {}) { return esFrom === 'snapshot' ? 3 * minute : 6 * minute; } - async start(esArgs = [], esEnvVars) { + async start() { let installPath; if (esFrom === 'source') { @@ -86,13 +94,7 @@ export function createLegacyEsTestCluster(options = {}) { await cluster.start(installPath, { password: config.password, - esArgs: [ - `cluster.name=${clusterName}`, - `http.port=${port}`, - 'discovery.type=single-node', - `transport.port=${transportPort}`, - ...esArgs, - ], + esArgs, esEnvVars, }); }