* add FTR test for aborted requests error name * delete unused file * wait for the request to fire before cancellation
This commit is contained in:
parent
a9b2cf55b7
commit
1c553b752c
8
test/plugin_functional/plugins/core_http/kibana.json
Normal file
8
test/plugin_functional/plugins/core_http/kibana.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"id": "coreHttp",
|
||||
"version": "0.0.1",
|
||||
"kibanaVersion": "kibana",
|
||||
"configPath": ["core_http"],
|
||||
"server": true,
|
||||
"ui": true
|
||||
}
|
14
test/plugin_functional/plugins/core_http/package.json
Normal file
14
test/plugin_functional/plugins/core_http/package.json
Normal file
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"name": "core_http",
|
||||
"version": "1.0.0",
|
||||
"main": "target/test/plugin_functional/plugins/core_http",
|
||||
"kibana": {
|
||||
"version": "kibana",
|
||||
"templateVersion": "1.0.0"
|
||||
},
|
||||
"license": "SSPL-1.0 OR Elastic License 2.0",
|
||||
"scripts": {
|
||||
"kbn": "node ../../../../scripts/kbn.js",
|
||||
"build": "rm -rf './target' && ../../../../node_modules/.bin/tsc"
|
||||
}
|
||||
}
|
13
test/plugin_functional/plugins/core_http/public/index.ts
Normal file
13
test/plugin_functional/plugins/core_http/public/index.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { PluginInitializer } from 'kibana/public';
|
||||
import { CoreHttpPlugin, CoreHttpPluginSetup, CoreHttpPluginStart } from './plugin';
|
||||
|
||||
export const plugin: PluginInitializer<CoreHttpPluginSetup, CoreHttpPluginStart> = () =>
|
||||
new CoreHttpPlugin();
|
46
test/plugin_functional/plugins/core_http/public/plugin.tsx
Normal file
46
test/plugin_functional/plugins/core_http/public/plugin.tsx
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { Plugin, CoreSetup } from 'kibana/public';
|
||||
|
||||
export class CoreHttpPlugin implements Plugin<CoreHttpPluginSetup, CoreHttpPluginStart> {
|
||||
public setup({ http }: CoreSetup, deps: {}) {
|
||||
const tryRequestCancellation = async () => {
|
||||
const abortController = new AbortController();
|
||||
|
||||
const errorNamePromise = http
|
||||
.get('/api/core_http/never_reply', { signal: abortController.signal })
|
||||
.then(
|
||||
() => {
|
||||
return undefined;
|
||||
},
|
||||
(e) => {
|
||||
return e.name;
|
||||
}
|
||||
);
|
||||
|
||||
// simulating 'real' cancellation by awaiting a bit
|
||||
window.setTimeout(() => {
|
||||
abortController.abort();
|
||||
}, 100);
|
||||
|
||||
return errorNamePromise;
|
||||
};
|
||||
|
||||
return {
|
||||
tryRequestCancellation,
|
||||
};
|
||||
}
|
||||
|
||||
public start() {}
|
||||
|
||||
public stop() {}
|
||||
}
|
||||
|
||||
export type CoreHttpPluginSetup = ReturnType<CoreHttpPlugin['setup']>;
|
||||
export type CoreHttpPluginStart = ReturnType<CoreHttpPlugin['start']>;
|
11
test/plugin_functional/plugins/core_http/server/index.ts
Normal file
11
test/plugin_functional/plugins/core_http/server/index.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { CoreHttpPlugin } from './plugin';
|
||||
|
||||
export const plugin = () => new CoreHttpPlugin();
|
30
test/plugin_functional/plugins/core_http/server/plugin.ts
Normal file
30
test/plugin_functional/plugins/core_http/server/plugin.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import type { Plugin, CoreSetup } from 'kibana/server';
|
||||
|
||||
export class CoreHttpPlugin implements Plugin {
|
||||
public setup(core: CoreSetup, deps: {}) {
|
||||
const router = core.http.createRouter();
|
||||
router.get(
|
||||
{
|
||||
path: '/api/core_http/never_reply',
|
||||
validate: false,
|
||||
},
|
||||
async (ctx, req, res) => {
|
||||
// need the endpoint to never reply to test request cancelation on the client side.
|
||||
await new Promise(() => undefined);
|
||||
return res.ok();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public start() {}
|
||||
|
||||
public stop() {}
|
||||
}
|
18
test/plugin_functional/plugins/core_http/tsconfig.json
Normal file
18
test/plugin_functional/plugins/core_http/tsconfig.json
Normal file
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"extends": "../../../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "./target",
|
||||
"skipLibCheck": true
|
||||
},
|
||||
"include": [
|
||||
"index.ts",
|
||||
"public/**/*.ts",
|
||||
"public/**/*.tsx",
|
||||
"server/**/*.ts",
|
||||
"../../../../typings/**/*",
|
||||
],
|
||||
"exclude": [],
|
||||
"references": [
|
||||
{ "path": "../../../../src/core/tsconfig.json" }
|
||||
]
|
||||
}
|
|
@ -2,7 +2,13 @@
|
|||
"id": "coreProviderPlugin",
|
||||
"version": "0.0.1",
|
||||
"kibanaVersion": "kibana",
|
||||
"optionalPlugins": ["corePluginA", "corePluginB", "licensing", "globalSearchTest"],
|
||||
"optionalPlugins": [
|
||||
"corePluginA",
|
||||
"corePluginB",
|
||||
"coreHttp",
|
||||
"licensing",
|
||||
"globalSearchTest"
|
||||
],
|
||||
"server": false,
|
||||
"ui": true
|
||||
}
|
||||
|
|
33
test/plugin_functional/test_suites/core_plugins/http.ts
Normal file
33
test/plugin_functional/test_suites/core_plugins/http.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { PluginFunctionalProviderContext } from '../../services';
|
||||
|
||||
export default function ({ getService, getPageObjects }: PluginFunctionalProviderContext) {
|
||||
const PageObjects = getPageObjects(['common']);
|
||||
const browser = getService('browser');
|
||||
|
||||
const getCancelationErrorName = async () => {
|
||||
return await browser.executeAsync(async (cb) => {
|
||||
const errorName = await window._coreProvider.setup.plugins.coreHttp.tryRequestCancellation();
|
||||
cb(errorName);
|
||||
});
|
||||
};
|
||||
|
||||
describe('http requests', () => {
|
||||
beforeEach(async () => {
|
||||
await PageObjects.common.navigateToApp('home');
|
||||
});
|
||||
|
||||
it('returns correct name for aborted requests', async () => {
|
||||
const canceledErrorName = await getCancelationErrorName();
|
||||
expect(canceledErrorName).to.eql('AbortError');
|
||||
});
|
||||
});
|
||||
}
|
|
@ -21,5 +21,6 @@ export default function ({ loadTestFile }: PluginFunctionalProviderContext) {
|
|||
loadTestFile(require.resolve('./rendering'));
|
||||
loadTestFile(require.resolve('./chrome_help_menu_links'));
|
||||
loadTestFile(require.resolve('./history_block'));
|
||||
loadTestFile(require.resolve('./http'));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue