mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
# Backport This will backport the following commits from `main` to `9.0`: - [[FTR] Added pause on error when error happens !! (#216165)](https://github.com/elastic/kibana/pull/216165) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Shahzad","email":"shahzad31comp@gmail.com"},"sourceCommit":{"committedDate":"2025-04-14T11:02:16Z","message":"[FTR] Added pause on error when error happens !! (#216165)\n\n## Summary\n\nAdded pause on error when error happens !!\n\n<img width=\"1728\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/1d649224-64a0-4a22-b526-9fdbd348efb0\"\n/>\n\n---------\n\nCo-authored-by: Dzmitry Lemechko <dzmitry.lemechko@elastic.co>","sha":"92556a37a70de82a09276187b24f21354e823165","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","ci:project-deploy-observability","backport:version","v9.1.0","v8.19.0","v9.0.1"],"title":"[FTR] Added pause on error when error happens !!","number":216165,"url":"https://github.com/elastic/kibana/pull/216165","mergeCommit":{"message":"[FTR] Added pause on error when error happens !! (#216165)\n\n## Summary\n\nAdded pause on error when error happens !!\n\n<img width=\"1728\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/1d649224-64a0-4a22-b526-9fdbd348efb0\"\n/>\n\n---------\n\nCo-authored-by: Dzmitry Lemechko <dzmitry.lemechko@elastic.co>","sha":"92556a37a70de82a09276187b24f21354e823165"}},"sourceBranch":"main","suggestedTargetBranches":["8.x","9.0"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/216165","number":216165,"mergeCommit":{"message":"[FTR] Added pause on error when error happens !! (#216165)\n\n## Summary\n\nAdded pause on error when error happens !!\n\n<img width=\"1728\" alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/1d649224-64a0-4a22-b526-9fdbd348efb0\"\n/>\n\n---------\n\nCo-authored-by: Dzmitry Lemechko <dzmitry.lemechko@elastic.co>","sha":"92556a37a70de82a09276187b24f21354e823165"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.0","label":"v9.0.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Shahzad <shahzad31comp@gmail.com>
This commit is contained in:
parent
986555cc9f
commit
c097111a82
2 changed files with 74 additions and 3 deletions
|
@ -145,6 +145,7 @@ export function runFtrCli() {
|
|||
'throttle',
|
||||
'headless',
|
||||
'dry-run',
|
||||
'pauseOnError',
|
||||
],
|
||||
help: `
|
||||
--config=path path to a config file (either this or --journey is required)
|
||||
|
@ -170,6 +171,7 @@ export function runFtrCli() {
|
|||
--throttle enable network throttling in Chrome browser
|
||||
--headless run browser in headless mode
|
||||
--dry-run report tests without executing them
|
||||
--pauseOnError pause test runner on error
|
||||
`,
|
||||
},
|
||||
}
|
||||
|
|
|
@ -6,13 +6,18 @@
|
|||
* your election, the "Elastic License 2.0", the "GNU Affero General Public
|
||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import chalk from 'chalk';
|
||||
import { relative } from 'path';
|
||||
import { REPO_ROOT } from '@kbn/repo-info';
|
||||
import { createAssignmentProxy } from './assignment_proxy';
|
||||
import { wrapFunction } from './wrap_function';
|
||||
import { wrapRunnableArgs } from './wrap_runnable_args';
|
||||
|
||||
// Add a global configuration for pauseOnError
|
||||
const testConfig = {
|
||||
pauseOnError: process.argv.includes('--pauseOnError'),
|
||||
};
|
||||
|
||||
const allTestsSkippedCache = new WeakMap();
|
||||
function allTestsAreSkipped(suite) {
|
||||
// cache result for each suite so we don't have to traverse over and over
|
||||
|
@ -39,6 +44,63 @@ function allTestsAreSkipped(suite) {
|
|||
return childrenSkipped;
|
||||
}
|
||||
|
||||
function createErrorPauseHandler() {
|
||||
return async (err, test, callback) => {
|
||||
// Check if pauseOnError is enabled globally or for this specific test
|
||||
if (testConfig.pauseOnError) {
|
||||
const originalTimeout = test.timeout();
|
||||
// Set minimum pause timeout to 10 minutes (600000 ms)
|
||||
const minPauseTimeout = 600000;
|
||||
// Extend timeout if it's less than 10 minutes
|
||||
if (originalTimeout < minPauseTimeout) {
|
||||
test.timeout(minPauseTimeout);
|
||||
}
|
||||
|
||||
// Create a more informative pause message
|
||||
const pauseMessage = chalk.bold.yellow(`
|
||||
!!!!! ${chalk.red('TEST PAUSED ON ERROR')} !!!!!
|
||||
${chalk.blue('File:')} ${test.file}
|
||||
${chalk.blue('Test:')} ${test.title}
|
||||
${chalk.red('Error:')} ${err.message}
|
||||
|
||||
${chalk.yellow('Pausing test execution. Press Ctrl+C to exit.')}
|
||||
|
||||
`);
|
||||
|
||||
// Use console.error to ensure the message is visible
|
||||
console.error(pauseMessage);
|
||||
|
||||
return new Promise((resolve) => {
|
||||
// Set a timeout to automatically resume after 10 minutes
|
||||
const pauseTimeout = setTimeout(() => {
|
||||
console.error('Pause timeout exceeded. Resuming test execution.');
|
||||
resolve();
|
||||
// Restore the original timeout
|
||||
test.timeout(originalTimeout);
|
||||
// Clear the timeout to prevent memory leaks
|
||||
clearTimeout(pauseTimeout);
|
||||
|
||||
// call the callback to continue the test run
|
||||
callback();
|
||||
}, minPauseTimeout);
|
||||
|
||||
// Set up a way to manually interrupt
|
||||
const interruptHandler = () => {
|
||||
clearTimeout(pauseTimeout);
|
||||
console.error(chalk.bold.red('\nTest run interrupted by user.'));
|
||||
process.exit(1);
|
||||
};
|
||||
|
||||
// Attach the interrupt handler
|
||||
process.once('SIGINT', interruptHandler);
|
||||
});
|
||||
}
|
||||
|
||||
// Always trigger the existing test failure lifecycle hook
|
||||
await callback();
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('../lifecycle').Lifecycle} lifecycle
|
||||
* @param {any} context
|
||||
|
@ -54,6 +116,9 @@ export function decorateMochaUi(lifecycle, context, { rootTags }) {
|
|||
// suite is not the first suite
|
||||
let suiteCount = 0;
|
||||
|
||||
// Create a error pause handler specific to this lifecycle
|
||||
const errorPauseHandler = createErrorPauseHandler(lifecycle);
|
||||
|
||||
/**
|
||||
* Wrap the describe() function in the mocha UI to ensure
|
||||
* that the first call made when defining a test file is a
|
||||
|
@ -136,7 +201,9 @@ export function decorateMochaUi(lifecycle, context, { rootTags }) {
|
|||
return wrapNonSuiteFunction(
|
||||
name,
|
||||
wrapRunnableArgs(fn, lifecycle, async (err, test) => {
|
||||
await lifecycle.testFailure.trigger(err, test);
|
||||
await errorPauseHandler(err, test, async () => {
|
||||
await lifecycle.testFailure.trigger(err, test);
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
@ -154,7 +221,9 @@ export function decorateMochaUi(lifecycle, context, { rootTags }) {
|
|||
return wrapNonSuiteFunction(
|
||||
name,
|
||||
wrapRunnableArgs(fn, lifecycle, async (err, test) => {
|
||||
await lifecycle.testHookFailure.trigger(err, test);
|
||||
await errorPauseHandler(err, test, async () => {
|
||||
await lifecycle.testHookFailure.trigger(err, test);
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue