e2ed
Version:
E2E testing framework over Playwright
60 lines (59 loc) • 2.92 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.runRetry = void 0;
const node_child_process_1 = require("node:child_process");
const node_path_1 = require("node:path");
const internal_1 = require("../../constants/internal");
const config_1 = require("../config");
const error_1 = require("../error");
const fs_1 = require("../fs");
const getDurationWithUnits_1 = require("../getDurationWithUnits");
const tests_1 = require("../tests");
const getTestsSubprocessForkOptions_1 = require("./getTestsSubprocessForkOptions");
const testsSubprocessForkOptions = (0, getTestsSubprocessForkOptions_1.getTestsSubprocessForkOptions)();
const pathToRunTestsSubprocess = (0, node_path_1.join)(internal_1.INSTALLED_E2ED_DIRECTORY_PATH, 'bin', 'runTestsSubprocess.js');
/**
* Runs one retry of remaining tests.
* @internal
*/
const runRetry = (runRetryOptions) => new Promise((resolve, reject) => {
if (tests_1.testsSubprocess?.killed === false) {
tests_1.testsSubprocess.kill();
}
void (0, fs_1.writeLogEventTime)('NaN');
const { runLabel } = runRetryOptions;
const newTestsSubprocess = (0, node_child_process_1.fork)(pathToRunTestsSubprocess, testsSubprocessForkOptions);
let timeoutId;
(0, tests_1.setTestsSubprocess)(newTestsSubprocess);
newTestsSubprocess.on('error', reject);
newTestsSubprocess.on('exit', (exitCode) => {
const error = new error_1.E2edError(`Tests subprocess with label "${runLabel}" exit with non-zero exit code ${String(exitCode)}`);
clearTimeout(timeoutId);
return exitCode === 0 ? resolve() : reject(error);
});
newTestsSubprocess.send(runRetryOptions);
const { testIdleTimeout } = (0, config_1.getFullPackConfig)();
const interruptTimeout = 2 * testIdleTimeout;
const killByTimeout = (reason = 'timeout') => {
if (!newTestsSubprocess.killed) {
newTestsSubprocess.kill();
}
const timeoutWithUnits = (0, getDurationWithUnits_1.getDurationWithUnits)(interruptTimeout);
const error = new error_1.E2edError(`Tests subprocess with label "${runLabel}" did not respond within ${timeoutWithUnits} and was killed`, { reason });
reject(error);
};
const resetInterruptTimeout = () => {
clearTimeout(timeoutId);
void (0, fs_1.getLastLogEventTimeInMs)().then((lastLogEventTimeInMs) => {
if (Number.isInteger(lastLogEventTimeInMs) &&
Date.now() - lastLogEventTimeInMs > interruptTimeout) {
const lastLogEventTime = new Date(lastLogEventTimeInMs).toISOString();
killByTimeout(`last log event time (${lastLogEventTime}) is outdated`);
}
});
timeoutId = setTimeout(killByTimeout, interruptTimeout);
};
resetInterruptTimeout();
newTestsSubprocess.on('message', resetInterruptTimeout);
});
exports.runRetry = runRetry;