From cf47ec3383aafad1f58fe0be5265eb0ba62a02df Mon Sep 17 00:00:00 2001 From: uid11 Date: Wed, 6 Mar 2024 03:27:35 +0300 Subject: [PATCH] FI-765 fix: writes HTML report after exit signals to `dockerEntrypoint.sh` --- autotests/bin/runDocker.sh | 2 ++ bin/dockerEntrypoint.sh | 3 ++- src/types/global.d.ts | 2 +- src/utils/end/setProcessEndHandlers.ts | 6 ++++-- src/utils/error/E2edError.ts | 2 +- src/utils/events/registerEndE2edRunEvent.ts | 8 ++++++++ src/utils/report/writeHtmlReport.ts | 2 +- src/utils/retry/runRetry.ts | 3 ++- src/utils/valueToString/wrapStringForLogs.ts | 2 +- 9 files changed, 22 insertions(+), 8 deletions(-) diff --git a/autotests/bin/runDocker.sh b/autotests/bin/runDocker.sh index c175dc35..ac229199 100755 --- a/autotests/bin/runDocker.sh +++ b/autotests/bin/runDocker.sh @@ -22,6 +22,8 @@ fi onExit() { CONTAINER_ID=$(docker ps --filter "label=$CONTAINER_LABEL" --format "{{.ID}}") + sleep 4 + if [[ -z $CONTAINER_ID ]] then echo "Docker container from image $E2ED_DOCKER_IMAGE:$VERSION already stopped" diff --git a/bin/dockerEntrypoint.sh b/bin/dockerEntrypoint.sh index b60e7cb7..ca762f33 100755 --- a/bin/dockerEntrypoint.sh +++ b/bin/dockerEntrypoint.sh @@ -14,7 +14,8 @@ onExit() { if [[ $PID ]] && ps -p $PID > /dev/null then echo "$PID is running" - kill $PID + kill -USR1 $PID + sleep 4 fi restoreE2edPackage; diff --git a/src/types/global.d.ts b/src/types/global.d.ts index f6f39428..ae97f9dd 100644 --- a/src/types/global.d.ts +++ b/src/types/global.d.ts @@ -21,7 +21,7 @@ declare module 'bin-v8-flags-filter' { }>; /** - * Filters out nodejs cli options and runs node module on cliPath. + * Filters out `nodejs` cli options and runs node module on `cliPath`. */ const v8FlagsFilter: (cliPath: string, options: Options) => void; diff --git a/src/utils/end/setProcessEndHandlers.ts b/src/utils/end/setProcessEndHandlers.ts index f0b6045a..ba04c764 100644 --- a/src/utils/end/setProcessEndHandlers.ts +++ b/src/utils/end/setProcessEndHandlers.ts @@ -5,7 +5,7 @@ import {generalLog} from '../generalLog'; import {endE2ed} from './endE2ed'; /** - * nodejs e2ed process end hanlder. + * `nodejs` e2ed process end hanlder. * @internal */ const endHandler = (signal: NodeJS.Signals): void => { @@ -15,10 +15,12 @@ const endHandler = (signal: NodeJS.Signals): void => { }; /** - * Set nodejs e2ed process end hanlders (SIGINT, SIGTERM). + * Set `nodejs` e2ed process end hanlders (`SIGHUP`, `SIGINT`, `SIGTERM`). * @internal */ export const setProcessEndHandlers = (): void => { + process.on('SIGHUP', endHandler); process.on('SIGINT', endHandler); process.on('SIGTERM', endHandler); + process.on('SIGUSR1', endHandler); }; diff --git a/src/utils/error/E2edError.ts b/src/utils/error/E2edError.ts index ca0b0712..7d1342a4 100644 --- a/src/utils/error/E2edError.ts +++ b/src/utils/error/E2edError.ts @@ -85,7 +85,7 @@ export class E2edError extends Error { } /** - * Custom presentation of error for nodejs `inspect`. + * Custom presentation of error for `nodejs` `inspect`. */ [inspect.custom](): string { return this.toString(); diff --git a/src/utils/events/registerEndE2edRunEvent.ts b/src/utils/events/registerEndE2edRunEvent.ts index 8eb8a495..79b8a5ee 100644 --- a/src/utils/events/registerEndE2edRunEvent.ts +++ b/src/utils/events/registerEndE2edRunEvent.ts @@ -10,11 +10,19 @@ import {runAfterPackFunctions} from './runAfterPackFunctions'; import type {ReportData} from '../../types/internal'; +let isEndAlreadyCalled = false; + /** * Registers end e2ed run event (for report) after closing of all tests. * @internal */ export const registerEndE2edRunEvent = async (): Promise => { + if (isEndAlreadyCalled) { + return; + } + + isEndAlreadyCalled = true; + generalLog('Starting to close e2ed...'); let reportData: ReportData | undefined; diff --git a/src/utils/report/writeHtmlReport.ts b/src/utils/report/writeHtmlReport.ts index 2882ba94..d1dd7576 100644 --- a/src/utils/report/writeHtmlReport.ts +++ b/src/utils/report/writeHtmlReport.ts @@ -12,7 +12,7 @@ import {renderReportToHtml} from './render'; import type {FilePathFromRoot, ReportData, UtcTimeInMs} from '../../types/internal'; /** - * Writes HTML report (report.html file) with test runs results. + * Writes HTML report (`report.html` file) with test runs results. * @internal */ export const writeHtmlReport = async (reportData: ReportData): Promise => { diff --git a/src/utils/retry/runRetry.ts b/src/utils/retry/runRetry.ts index 1eccb87b..74cb9c52 100644 --- a/src/utils/retry/runRetry.ts +++ b/src/utils/retry/runRetry.ts @@ -40,7 +40,8 @@ export const runRetry = (runRetryOptions: RunRetryOptions): Promise => setTestsSubprocess(newTestsSubprocess); newTestsSubprocess.on('error', reject); - newTestsSubprocess.on('exit', (exitCode) => { + + newTestsSubprocess.on('exit', (exitCode): void => { const error = new E2edError( `Tests subprocess with label "${runLabel}" exit with non-zero exit code ${String( exitCode, diff --git a/src/utils/valueToString/wrapStringForLogs.ts b/src/utils/valueToString/wrapStringForLogs.ts index d7ea6b7a..f83ec999 100644 --- a/src/utils/valueToString/wrapStringForLogs.ts +++ b/src/utils/valueToString/wrapStringForLogs.ts @@ -17,7 +17,7 @@ function toMultipleString(this: StringForLogs): string { /** * If the text consists of several lines, replaces the text with an object - * with a more beautiful presentation through nodejs `inspect`. + * with a more beautiful presentation through `nodejs` `inspect`. * @internal */ export const wrapStringForLogs = (text: string, options?: Options): StringForLogs | string => {