Skip to content

Commit

Permalink
[Code] Add api test for multi code node setup
Browse files Browse the repository at this point in the history
  • Loading branch information
spacedragon committed Feb 25, 2019
1 parent 821e47b commit 66ea9fc
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 1 deletion.
118 changes: 118 additions & 0 deletions x-pack/plugins/code/server/__tests__/multi_node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import getPort from 'get-port';
import { resolve } from 'path';
import { Root } from '../../../../../src/core/server/root';
import {
createRootWithCorePlugins,
request,
startTestServers,
} from '../../../../../src/test_utils/kbn_server';

describe('code in multiple nodes', () => {
const codeNodeUuid = 'c4add484-0cba-4e05-86fe-4baa112d9e53';
let port: number;
let codeNode: Root;
let nonCodeNode: Root;

let servers: any;
const pluginPaths = resolve(__dirname, '../../../../../node_modules/x-pack');

async function startServers() {
port = await getPort();
servers = await startTestServers({
adjustTimeout: t => {
// @ts-ignore
this.timeout(t);
},
settings: {
kbn: {
server: {
uuid: codeNodeUuid,
port,
},
plugins: { paths: [pluginPaths] },
xpack: {
upgrade_assistant: {
enabled: false,
},
code: {
codeNode: true,
},
security: {
enabled: false,
},
},
},
},
});
codeNode = servers.root;
await startNonCodeNodeKibana();
}

async function startNonCodeNodeKibana() {
const setting = {
plugins: { paths: [pluginPaths] },
xpack: {
upgrade_assistant: {
enabled: false,
},
code: { codeNode: false },
security: {
enabled: false,
},
},
};
nonCodeNode = createRootWithCorePlugins(setting);
await nonCodeNode.start();
}
// @ts-ignore
before(startServers);

// @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);
});

it('Non-code node setup should be ok', async () => {
await request.get(nonCodeNode, '/api/code/setup').expect(200);
});

it('Non-code node setup should fail if code node is shutdown', async () => {
await codeNode.shutdown();
await request.get(nonCodeNode, '/api/code/setup').expect(502);
await codeNode.start();
await delay(2000);
await request.get(nonCodeNode, '/api/code/setup').expect(200);
// @ts-ignore
}).timeout(20000);

it('cluster uuid should equals Code node uuid', async () => {
const url = `http://localhost:${port}`;
await request.get(codeNode, '/api/code/cluster').expect(200, {
uuid: codeNodeUuid,
url,
});
await request.get(nonCodeNode, '/api/code/cluster').expect(200, {
uuid: codeNodeUuid,
url,
});
});
});
2 changes: 1 addition & 1 deletion x-pack/plugins/code/server/routes/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function clusterRoute(server: Server, codeNodeClient: CodeNodeClient, log
server.securedRoute({
path: '/api/code/cluster',
method: 'GET',
requireAdmin: true,
requireAdmin: false,
async handler() {
const info = codeNodeClient.getCodeNodeInfo();
if (info) {
Expand Down

0 comments on commit 66ea9fc

Please sign in to comment.