Run mocha test (for review) (#35924)
* [Code]: Make sure code mocha test could be run on CI * [Code] fix lsp_service tests * [Code] fix a problem that process can't exit normal when running gulp * Ignore cert check for mocha tests * Don't reuse root
This commit is contained in:
parent
bc90140f8e
commit
c41010760e
|
@ -50,6 +50,10 @@ export function statusMixin(kbnServer, server, config) {
|
|||
});
|
||||
oppsy.start(config.get('ops.interval'));
|
||||
|
||||
server.events.on('stop', () => {
|
||||
oppsy.stop();
|
||||
});
|
||||
|
||||
// init routes
|
||||
registerStatusPage(kbnServer, server, config);
|
||||
registerStatusApi(kbnServer, server, config);
|
||||
|
|
|
@ -42,8 +42,8 @@
|
|||
"@storybook/react": "^5.0.5",
|
||||
"@storybook/theming": "^5.0.5",
|
||||
"@types/angular": "1.6.50",
|
||||
"@types/boom": "^7.2.0",
|
||||
"@types/base64-js": "^1.2.5",
|
||||
"@types/boom": "^7.2.0",
|
||||
"@types/cheerio": "^0.22.10",
|
||||
"@types/chroma-js": "^1.4.1",
|
||||
"@types/color": "^3.0.0",
|
||||
|
@ -53,9 +53,9 @@
|
|||
"@types/d3-time": "^1.0.7",
|
||||
"@types/d3-time-format": "^2.1.0",
|
||||
"@types/elasticsearch": "^5.0.30",
|
||||
"@types/file-saver": "^2.0.0",
|
||||
"@types/git-url-parse": "^9.0.0",
|
||||
"@types/glob": "^7.1.1",
|
||||
"@types/file-saver": "^2.0.0",
|
||||
"@types/graphql": "^0.13.1",
|
||||
"@types/hapi-auth-cookie": "^9.1.0",
|
||||
"@types/history": "^4.6.2",
|
||||
|
@ -65,8 +65,8 @@
|
|||
"@types/json-stable-stringify": "^1.0.32",
|
||||
"@types/jsonwebtoken": "^7.2.7",
|
||||
"@types/lodash": "^3.10.1",
|
||||
"@types/mkdirp": "^0.5.2",
|
||||
"@types/mime": "^2.0.1",
|
||||
"@types/mkdirp": "^0.5.2",
|
||||
"@types/mocha": "^5.2.6",
|
||||
"@types/nock": "^9.3.0",
|
||||
"@types/node": "^10.12.27",
|
||||
|
|
|
@ -31,7 +31,13 @@ function prepareProject(url: string, p: string) {
|
|||
return new Promise(resolve => {
|
||||
if (!fs.existsSync(p)) {
|
||||
rimraf(p, error => {
|
||||
Git.Clone.clone(url, p).then(repo => {
|
||||
Git.Clone.clone(url, p, {
|
||||
fetchOpts: {
|
||||
callbacks: {
|
||||
certificateCheck: () => 0,
|
||||
},
|
||||
},
|
||||
}).then(repo => {
|
||||
resolve(repo);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -106,7 +106,13 @@ describe('git_operations', () => {
|
|||
return new Promise(resolve => {
|
||||
if (!fs.existsSync(p)) {
|
||||
rimraf(p, error => {
|
||||
Git.Clone.clone(url, p).then(repo => {
|
||||
Git.Clone.clone(url, p, {
|
||||
fetchOpts: {
|
||||
callbacks: {
|
||||
certificateCheck: () => 0,
|
||||
},
|
||||
},
|
||||
}).then(repo => {
|
||||
resolve(repo);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -40,7 +40,7 @@ function prepareProject(url: string, p: string) {
|
|||
const opts: CloneOptions = {
|
||||
fetchOpts: {
|
||||
callbacks: {
|
||||
certificateCheck: () => 1,
|
||||
certificateCheck: () => 0,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
@ -39,7 +39,7 @@ function prepareProject(url: string, p: string) {
|
|||
const opts: CloneOptions = {
|
||||
fetchOpts: {
|
||||
callbacks: {
|
||||
certificateCheck: () => 1,
|
||||
certificateCheck: () => 0,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
@ -21,14 +21,33 @@ import { createTestServerOption } from '../test_utils';
|
|||
import { ConsoleLoggerFactory } from '../utils/console_logger_factory';
|
||||
|
||||
const filename = 'hello.ts';
|
||||
const packagejson = `
|
||||
{
|
||||
"name": "master",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"typescript": "~3.3.3333"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \\"Error: no test specified\\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
||||
`;
|
||||
describe('lsp_service tests', () => {
|
||||
async function prepareProject(repoPath: string) {
|
||||
mkdirp.sync(repoPath);
|
||||
const repo = await Git.Repository.init(repoPath, 0);
|
||||
const helloContent = "console.log('hello world');";
|
||||
fs.writeFileSync(path.join(repo.workdir(), filename), helloContent, 'utf8');
|
||||
fs.writeFileSync(path.join(repo.workdir(), 'package.json'), packagejson, 'utf8');
|
||||
const index = await repo.refreshIndex();
|
||||
await index.addByPath(filename);
|
||||
await index.addByPath('package.json');
|
||||
index.write();
|
||||
const treeId = await index.writeTree();
|
||||
const committer = Git.Signature.create('tester', 'test@test.com', Date.now() / 1000, 60);
|
||||
|
@ -72,7 +91,16 @@ describe('lsp_service tests', () => {
|
|||
|
||||
// @ts-ignore
|
||||
before(async () => {
|
||||
await prepareProject(path.join(serverOptions.repoPath, repoUri));
|
||||
const tmpRepo = path.join(serverOptions.repoPath, 'tmp');
|
||||
await prepareProject(tmpRepo);
|
||||
await Git.Clone.clone(`file://${tmpRepo}`, path.join(serverOptions.repoPath, repoUri), {
|
||||
bare: 1,
|
||||
fetchOpts: {
|
||||
callbacks: {
|
||||
certificateCheck: () => 0,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
function comparePath(pathA: string, pathB: string) {
|
||||
|
@ -179,7 +207,7 @@ describe('lsp_service tests', () => {
|
|||
const realWorkspacePath = fs.realpathSync(workspacePath);
|
||||
|
||||
// @ts-ignore
|
||||
const handler = languageServer.languageServerHandlers[realWorkspacePath];
|
||||
const handler = await languageServer.languageServerHandlers[realWorkspacePath];
|
||||
const exitSpy = sinon.spy(handler, 'exit');
|
||||
const unloadSpy = sinon.spy(handler, 'unloadWorkspace');
|
||||
|
||||
|
|
|
@ -7,26 +7,69 @@
|
|||
import getPort from 'get-port';
|
||||
import { resolve } from 'path';
|
||||
import { Root } from 'src/core/server/root';
|
||||
|
||||
import {
|
||||
createRootWithCorePlugins,
|
||||
getKbnServer,
|
||||
request,
|
||||
startTestServers,
|
||||
} from '../../../../../src/test_utils/kbn_server';
|
||||
|
||||
const xpackOption = {
|
||||
upgrade_assistant: {
|
||||
enabled: false,
|
||||
},
|
||||
security: {
|
||||
enabled: false,
|
||||
},
|
||||
ccr: {
|
||||
enabled: false,
|
||||
},
|
||||
monitoring: {
|
||||
enabled: false,
|
||||
},
|
||||
beats: {
|
||||
enabled: false,
|
||||
},
|
||||
ilm: {
|
||||
enabled: false,
|
||||
},
|
||||
logstash: {
|
||||
enabled: false,
|
||||
},
|
||||
rollup: {
|
||||
enabled: false,
|
||||
},
|
||||
watcher: {
|
||||
enabled: false,
|
||||
},
|
||||
remote_clusters: {
|
||||
enabled: false,
|
||||
},
|
||||
reporting: {
|
||||
enabled: false,
|
||||
},
|
||||
task_manager: {
|
||||
enabled: false,
|
||||
},
|
||||
maps: {
|
||||
enabled: false,
|
||||
},
|
||||
oss_telemetry: {
|
||||
enabled: false,
|
||||
},
|
||||
};
|
||||
|
||||
describe('code in multiple nodes', () => {
|
||||
const codeNodeUuid = 'c4add484-0cba-4e05-86fe-4baa112d9e53';
|
||||
const nonodeNodeUuid = '22b75e04-0e50-4647-9643-6b1b1d88beaf';
|
||||
let codePort: number;
|
||||
let nonCodePort: number;
|
||||
let codeNode: Root;
|
||||
let nonCodeNode: Root;
|
||||
|
||||
let servers: any;
|
||||
const pluginPaths = resolve(__dirname, '../../../../../x-pack');
|
||||
|
||||
async function startServers() {
|
||||
codePort = await getPort();
|
||||
nonCodePort = await getPort();
|
||||
servers = await startTestServers({
|
||||
adjustTimeout: t => {
|
||||
// @ts-ignore
|
||||
|
@ -39,19 +82,12 @@ describe('code in multiple nodes', () => {
|
|||
port: codePort,
|
||||
},
|
||||
plugins: { paths: [pluginPaths] },
|
||||
xpack: {
|
||||
upgrade_assistant: {
|
||||
enabled: false,
|
||||
},
|
||||
security: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
xpack: xpackOption,
|
||||
},
|
||||
},
|
||||
});
|
||||
codeNode = servers.root;
|
||||
await startNonCodeNodeKibana();
|
||||
|
||||
await getKbnServer(servers.root).server.plugins.elasticsearch.waitUntilReady();
|
||||
}
|
||||
|
||||
async function startNonCodeNodeKibana() {
|
||||
|
@ -62,37 +98,33 @@ describe('code in multiple nodes', () => {
|
|||
},
|
||||
plugins: { paths: [pluginPaths] },
|
||||
xpack: {
|
||||
upgrade_assistant: {
|
||||
enabled: false,
|
||||
},
|
||||
...xpackOption,
|
||||
code: { codeNodeUrl: `http://localhost:${codePort}` },
|
||||
security: {
|
||||
enabled: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
nonCodeNode = createRootWithCorePlugins(setting);
|
||||
await nonCodeNode.setup();
|
||||
await nonCodeNode.start();
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
before(startServers);
|
||||
before(async function() {
|
||||
nonCodePort = await getPort();
|
||||
codePort = await getPort();
|
||||
|
||||
// @ts-ignore
|
||||
await startServers.bind(this)();
|
||||
await startNonCodeNodeKibana();
|
||||
});
|
||||
|
||||
// @ts-ignore
|
||||
after(async function() {
|
||||
// @ts-ignore
|
||||
this.timeout(10000);
|
||||
await nonCodeNode.shutdown();
|
||||
await servers.stop();
|
||||
});
|
||||
|
||||
function delay(ms: number) {
|
||||
return new Promise(resolve1 => {
|
||||
setTimeout(resolve1, ms);
|
||||
});
|
||||
}
|
||||
|
||||
it('Code node setup should be ok', async () => {
|
||||
await request.get(codeNode, '/api/code/setup').expect(200);
|
||||
await request.get(servers.root, '/api/code/setup').expect(200);
|
||||
});
|
||||
|
||||
it('Non-code node setup should be ok', async () => {
|
||||
|
@ -100,12 +132,13 @@ describe('code in multiple nodes', () => {
|
|||
});
|
||||
|
||||
it('Non-code node setup should fail if code node is shutdown', async () => {
|
||||
await codeNode.shutdown();
|
||||
await delay(2000);
|
||||
await servers.root.shutdown();
|
||||
await request.get(nonCodeNode, '/api/code/setup').expect(502);
|
||||
await codeNode.setup();
|
||||
await delay(2000);
|
||||
await request.get(nonCodeNode, '/api/code/setup').expect(200);
|
||||
|
||||
// TODO restart root clearly is hard to do during platform migration
|
||||
// A clear way is to createEsCluster individually and not reuse the
|
||||
// same root
|
||||
|
||||
// @ts-ignore
|
||||
}).timeout(20000);
|
||||
});
|
||||
|
|
|
@ -77,6 +77,10 @@ async function getCodeNodeUuid(url: string, log: Logger) {
|
|||
}
|
||||
|
||||
export function init(server: Server, options: any) {
|
||||
if (!options.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
const log = new Logger(server);
|
||||
const serverOptions = new ServerOptions(options, server.config());
|
||||
const xpackMainPlugin: XPackMainPlugin = server.plugins.xpack_main;
|
||||
|
@ -252,4 +256,12 @@ async function initCodeNode(server: Server, serverOptions: ServerOptions, log: L
|
|||
installRoute(codeServerRouter, lspService);
|
||||
lspRoute(codeServerRouter, lspService, serverOptions);
|
||||
setupRoute(codeServerRouter);
|
||||
|
||||
server.events.on('stop', () => {
|
||||
if (!serverOptions.disableIndexScheduler) {
|
||||
indexScheduler.stop();
|
||||
}
|
||||
updateScheduler.stop();
|
||||
queue.destroy();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -60,4 +60,5 @@ export class Esqueue extends EventEmitter {
|
|||
workerFn: WorkerFn<P, R>,
|
||||
opts?: Pick<WorkerOptions, Exclude<keyof WorkerOptions, 'logger'>>
|
||||
): W;
|
||||
public destroy(): void;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,13 @@ export class TestRepoManager {
|
|||
if (!fs.existsSync(path)) {
|
||||
rimraf(path, error => {
|
||||
console.log(`begin to import ${url} to ${path}`);
|
||||
Git.Clone.clone(url, path).then(repo => {
|
||||
Git.Clone.clone(url, path, {
|
||||
fetchOpts: {
|
||||
callbacks: {
|
||||
certificateCheck: () => 0,
|
||||
},
|
||||
},
|
||||
}).then(repo => {
|
||||
console.log(`import ${url} done`);
|
||||
resolve(repo);
|
||||
});
|
||||
|
|
|
@ -39,6 +39,7 @@ describe('setupXPackMain()', () => {
|
|||
elasticsearch: mockElasticsearchPlugin,
|
||||
xpack_main: mockXPackMainPlugin
|
||||
},
|
||||
events: { on() {} },
|
||||
log() {},
|
||||
config() {},
|
||||
expose() {},
|
||||
|
|
|
@ -67,6 +67,7 @@ describe('XPackInfo', () => {
|
|||
|
||||
mockServer = sinon.stub({
|
||||
plugins: { elasticsearch: mockElasticsearchPlugin },
|
||||
events: { on() {} },
|
||||
log() { }
|
||||
});
|
||||
});
|
||||
|
|
|
@ -82,6 +82,10 @@ export class XPackInfo {
|
|||
continuePollingOnError: true
|
||||
});
|
||||
|
||||
server.events.on('stop', () => {
|
||||
this._poller.stop();
|
||||
});
|
||||
|
||||
this._license = new XPackInfoLicense(
|
||||
() => this._cache.response && this._cache.response.license
|
||||
);
|
||||
|
|
|
@ -26,7 +26,9 @@ function getPluginPaths(plugins, opts = {}) {
|
|||
const publicPaths = `plugins/${publicPath}/**/${testPath}/*.js`;
|
||||
|
||||
paths = paths.concat([indexPaths, commonPaths, serverPaths]);
|
||||
|
||||
if(plugin === 'code') {
|
||||
paths.push(`plugins/${serverPath}/**/${testPath}/*.ts`);
|
||||
}
|
||||
if (opts.browser) {
|
||||
paths = paths.concat(publicPaths);
|
||||
}
|
||||
|
|
|
@ -28,9 +28,7 @@ export default (gulp, { mocha }) => {
|
|||
gulp.task('testserver', () => {
|
||||
const globs = [
|
||||
'common/**/__tests__/**/*.js',
|
||||
'common/**/__tests__/**/*.ts',
|
||||
'server/**/__tests__/**/*.js',
|
||||
'server/**/__tests__/**/*.ts',
|
||||
].concat(forPluginServerTests());
|
||||
return gulp.src(globs, { read: false })
|
||||
.pipe(mocha(MOCHA_OPTIONS));
|
||||
|
|
Loading…
Reference in a new issue