add FTR test for aborted requests error name (#97086) (#97484)

* add FTR test for aborted requests error name

* delete unused file

* wait for the request to fire before cancellation
This commit is contained in:
Pierre Gayvallet 2021-04-19 19:56:22 +02:00 committed by GitHub
parent a9b2cf55b7
commit 1c553b752c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 181 additions and 1 deletions

View file

@ -0,0 +1,8 @@
{
"id": "coreHttp",
"version": "0.0.1",
"kibanaVersion": "kibana",
"configPath": ["core_http"],
"server": true,
"ui": true
}

View 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"
}
}

View 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();

View 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']>;

View 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();

View 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() {}
}

View 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" }
]
}

View file

@ -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
}

View 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');
});
});
}

View file

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