Skip to content

Commit

Permalink
FI-765 fix: directly end e2ed on termination signals
Browse files Browse the repository at this point in the history
fix: add more temporary logs on termination signals
  • Loading branch information
uid11 committed Mar 15, 2024
1 parent 152c0aa commit 93a4101
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 30 deletions.
15 changes: 11 additions & 4 deletions autotests/bin/runDocker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set +u
CONTAINER_LABEL="e2ed"
DEBUG_PORT="${E2ED_DOCKER_DEBUG_PORT:-9229}"
DIR="${E2ED_WORKDIR:-$PWD}"
E2ED_TIMEOUT_FOR_GRACEFUL_SHUTDOWN_IN_SECONDS=16
MOUNTDIR="${E2ED_MOUNTDIR:-$DIR}"
WITH_DEBUG=$([[ -z $E2ED_DEBUG ]] && echo "" || echo "--env E2ED_DEBUG=$DEBUG_PORT --publish $DEBUG_PORT:$DEBUG_PORT --publish $((DEBUG_PORT + 1)):$((DEBUG_PORT + 1))")
VERSION=$(grep -m1 \"e2ed\": $DIR/package.json | cut -d '"' -f 4)
Expand All @@ -26,10 +27,16 @@ onExit() {
then
echo "Docker container from image $E2ED_DOCKER_IMAGE:$VERSION already stopped"
else
sleep 18
echo "runDocker will sleep $(($E2ED_TIMEOUT_FOR_GRACEFUL_SHUTDOWN_IN_SECONDS + 2)) for seconds"
sleep "$(($E2ED_TIMEOUT_FOR_GRACEFUL_SHUTDOWN_IN_SECONDS + 2))"

echo "Stop docker container from image $E2ED_DOCKER_IMAGE:$VERSION"
docker stop --time=60 $CONTAINER_ID
CONTAINER_ID=$(docker ps --filter "label=$CONTAINER_LABEL" --format "{{.ID}}")

if [[ ! -z $CONTAINER_ID ]]
then
echo "Stop docker container from image $E2ED_DOCKER_IMAGE:$VERSION"
docker stop --time=60 $CONTAINER_ID
fi
fi

exit
Expand All @@ -41,7 +48,7 @@ trap "onExit" EXIT

docker run \
--env E2ED_ORIGIN=$E2ED_ORIGIN \
--env E2ED_TIMEOUT_FOR_GRACEFUL_SHUTDOWN_IN_SECONDS=16 \
--env E2ED_TIMEOUT_FOR_GRACEFUL_SHUTDOWN_IN_SECONDS=$E2ED_TIMEOUT_FOR_GRACEFUL_SHUTDOWN_IN_SECONDS \
--env __INTERNAL_E2ED_PATH_TO_PACK=$1 \
--label $CONTAINER_LABEL \
--rm \
Expand Down
1 change: 1 addition & 0 deletions bin/dockerEntrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ onExit() {
echo "PID $PID is running"
kill -USR1 $PID

echo "dockerEntrypoint will sleep ${E2ED_TIMEOUT_FOR_GRACEFUL_SHUTDOWN_IN_SECONDS:-16} for seconds"
sleep "${E2ED_TIMEOUT_FOR_GRACEFUL_SHUTDOWN_IN_SECONDS:-16}"
fi

Expand Down
9 changes: 8 additions & 1 deletion src/utils/end/endE2ed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ export const endE2ed = (definedEndE2edReason: EndE2edReason): void => {
return;
}

generalLog(`End e2ed with reason "${definedEndE2edReason}"`);
const message = `End e2ed with reason "${definedEndE2edReason}"`;

// eslint-disable-next-line no-console
console.log(message);
generalLog(message);

setEndE2edReason(definedEndE2edReason);

if (testsSubprocess?.killed === false) {
// eslint-disable-next-line no-console
console.log('Kill tests subprocess');

testsSubprocess.kill();
}
};
5 changes: 5 additions & 0 deletions src/utils/end/setProcessEndHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ const endHandler = (signal: NodeJS.Signals): void => {
generalLog(message);

endE2ed(EndE2edReason.ProcessEndSignal);

// eslint-disable-next-line global-require, @typescript-eslint/no-var-requires
const {registerEndE2edRunEvent} = require<typeof import('../events')>('../events');

void registerEndE2edRunEvent();
};

/**
Expand Down
28 changes: 28 additions & 0 deletions src/utils/events/getReports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {ExitCode} from '../../constants/internal';

import {failMessage, generalLog, okMessage} from '../generalLog';
import {collectReportData, getLiteReport} from '../report';

import {collectFullEventsData} from './collectFullEventsData';

import type {LiteReport, ReportData} from '../../types/internal';

type Return = Readonly<{liteReport: LiteReport; reportData: ReportData}>;

/**
* Get report data and lite report.
* @internal
*/
export const getReports = async (): Promise<Return> => {
const fullEventsData = await collectFullEventsData();

const reportData = await collectReportData(fullEventsData);

const stateMessage = reportData.exitCode === ExitCode.Passed ? okMessage : failMessage;

generalLog(`Results of pack: ${stateMessage} ${reportData.summaryPackResults}`);

const liteReport = getLiteReport(reportData);

return {liteReport, reportData};
};
34 changes: 12 additions & 22 deletions src/utils/events/registerEndE2edRunEvent.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {ExitCode} from '../../constants/internal';

import {exitFromE2ed} from '../exit';
import {failMessage, generalLog, okMessage} from '../generalLog';
import {collectReportData, getLiteReport, writeHtmlReport, writeLiteJsonReport} from '../report';
import {generalLog} from '../generalLog';
import {setReadonlyProperty} from '../setReadonlyProperty';

import {collectFullEventsData} from './collectFullEventsData';
import {getReports} from './getReports';
import {runAfterPackFunctions} from './runAfterPackFunctions';
import {writeReports} from './writeReports';

import type {ReportData} from '../../types/internal';
import type {LiteReport, ReportData} from '../../types/internal';

let isEndAlreadyCalled = false;

Expand All @@ -23,20 +23,18 @@ export const registerEndE2edRunEvent = async (): Promise<void> => {

isEndAlreadyCalled = true;

generalLog('Starting to close e2ed...');
const message = 'Starting to close e2ed...';

// eslint-disable-next-line no-console
console.log(message);
generalLog(message);

let reportData: ReportData | undefined;

try {
const fullEventsData = await collectFullEventsData();

reportData = await collectReportData(fullEventsData);

const stateMessage = reportData.exitCode === ExitCode.Passed ? okMessage : failMessage;

generalLog(`Results of pack: ${stateMessage} ${reportData.summaryPackResults}`);
let liteReport: LiteReport | undefined;

const liteReport = getLiteReport(reportData);
({liteReport, reportData} = await getReports());

try {
await runAfterPackFunctions(liteReport);
Expand All @@ -52,15 +50,7 @@ export const registerEndE2edRunEvent = async (): Promise<void> => {
setReadonlyProperty(reportData, 'customReportProperties', customReportProperties);
}

const {liteReportFileName, reportFileName} = reportData;

if (liteReportFileName !== null) {
await writeLiteJsonReport(liteReport);
}

if (reportFileName !== null) {
await writeHtmlReport(reportData);
}
await writeReports({liteReport, reportData});
} catch (error) {
generalLog(
'Caught an error while collecting the report data or writing the HTML report and lite report',
Expand Down
21 changes: 21 additions & 0 deletions src/utils/events/writeReports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {writeHtmlReport, writeLiteJsonReport} from '../report';

import type {LiteReport, ReportData} from '../../types/internal';

type Options = Readonly<{liteReport: LiteReport; reportData: ReportData}>;

/**
* Writes HTML report and lite JSON report to corresponding files.
* @internal
*/
export const writeReports = async ({liteReport, reportData}: Options): Promise<void> => {
const {liteReportFileName, reportFileName} = reportData;

if (liteReportFileName !== null) {
await writeLiteJsonReport(liteReport);
}

if (reportFileName !== null) {
await writeHtmlReport(reportData);
}
};
4 changes: 2 additions & 2 deletions src/utils/packCompiler/compilePack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {getCompilerOptions} from './getCompilerOptions';

import type {UtcTimeInMs} from '../../types/internal';

type Result = Readonly<{
type Return = Readonly<{
compileErrors: readonly Readonly<Record<string, string>>[];
configCompileTimeWithUnits: string;
}>;
Expand All @@ -23,7 +23,7 @@ const unusedTsExceptErrorMessage = "Unused '@ts-expect-error' directive.";
* Compiles pack file before running tests (or tasks).
* @internal
*/
export const compilePack = (): Result => {
export const compilePack = (): Return => {
const startTimeInMs = Date.now() as UtcTimeInMs;

const {compilerOptions, parsingTsConfigError} = getCompilerOptions();
Expand Down
2 changes: 1 addition & 1 deletion src/utils/report/writeLiteJsonReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {getDurationWithUnits} from '../getDurationWithUnits';
import type {FilePathFromRoot, LiteReport, UtcTimeInMs} from '../../types/internal';

/**
* Writes lite JSON report (lite-report.json file) with test runs results
* Writes lite JSON report (`lite-report.json` file) with test runs results
* (and without test run logs).
* @internal
*/
Expand Down

0 comments on commit 93a4101

Please sign in to comment.