-
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.
[Code] Add api test for multi code node setup
- Loading branch information
spacedragon
committed
Feb 25, 2019
1 parent
821e47b
commit 66ea9fc
Showing
2 changed files
with
119 additions
and
1 deletion.
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
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, | ||
}); | ||
}); | ||
}); |
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