-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement esTestCluster test util (#13099)
* [es/tests] remove unused module * [testUtil/es] add utility for starting es nodes in tests * [ftr/tests] use esTestCluster util to start es * [es/tests/routes] use esTestCluster to start own es * [testUtils/kbnServer] disable uiSettings unless plugins are enabled * [testUtils/esTestCluster] use standard test es port by default * [server/http/tests] add esTestCluster to setup * [test/config] unify es test config into a single module * [testUtils/esTestCluster] directory is no longer configurable * [testUtils/esTestCluster] throw when es.start() is called again without es.stop() * [testUtils/esTestCluster] is* checks should not mutate state (cherry picked from commit 6748b22)
- Loading branch information
Showing
21 changed files
with
235 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export { startupEs } from './es'; | ||
export { startupKibana } from './kibana'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { resolve } from 'path'; | ||
import { esTestConfig } from './es_test_config'; | ||
|
||
import libesvm from 'libesvm'; | ||
|
||
const ESVM_DIR = resolve(__dirname, '../../../esvm/test_utils/es_test_cluster'); | ||
|
||
export class EsTestCluster { | ||
_branchesDownloaded = []; | ||
|
||
use(options = {}) { | ||
const { | ||
name, | ||
log = console.log, | ||
port = esTestConfig.getPort(), | ||
branch = esTestConfig.getBranch(), | ||
} = options; | ||
|
||
if (!name) { | ||
throw new Error('esTestCluster.use() requires { name }'); | ||
} | ||
|
||
// assigned in use.start(), reassigned in use.stop() | ||
let cluster; | ||
|
||
return { | ||
getStartTimeout: () => { | ||
return esTestConfig.getLibesvmStartTimeout(); | ||
}, | ||
|
||
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.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(); | ||
}, | ||
|
||
stop: async () => { | ||
if (cluster) { | ||
const c = cluster; | ||
cluster = null; | ||
await c.shutdown(); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
_isDownloadNeeded(branch) { | ||
if (process.env.ESVM_NO_FRESH || process.argv.includes('--esvm-no-fresh')) { | ||
return false; | ||
} | ||
|
||
if (this._branchesDownloaded.includes(branch)) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
export const esTestCluster = new EsTestCluster(); |
Oops, something went wrong.