Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Code] Add api test for multi code node setup #31460

Merged
merged 1 commit into from
Feb 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 () => {
spacedragon marked this conversation as resolved.
Show resolved Hide resolved
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