From 5d66bb879464adb2f23d764a3602f967748069d0 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Sat, 5 Jun 2021 14:54:07 +0900 Subject: ランダムにテストがコケるのを修正 (#7553) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Test shutdown * Revert "Test shutdown" This reverts commit 85182e7dd196cdd9ecb46cfb50adaabd04c5ba60. * Skip beforeShutdown in test * Wait shutdown in test * Revert "Skip beforeShutdown in test" This reverts commit 79c33ab53615e8fa4820d2abfc2494cba55c441c. * Revert "Revert "Skip beforeShutdown in test"" This reverts commit 3423133a137c79b64f3ff6ef9dbe433a441a47b0. --- test/utils.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/utils.ts') diff --git a/test/utils.ts b/test/utils.ts index 193017e265..e4c96d0e15 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -5,6 +5,7 @@ const FormData = require('form-data'); import * as childProcess from 'child_process'; import * as http from 'http'; import loadConfig from '../src/config/load'; +import { SIGKILL } from 'constants'; export const port = loadConfig().port; @@ -145,3 +146,19 @@ export function launchServer(callbackSpawnedProcess: (p: childProcess.ChildProce }); }; } + +export function shutdownServer(p: childProcess.ChildProcess, timeout = 20 * 1000) { + return new Promise((res, rej) => { + const t = setTimeout(() => { + p.kill(SIGKILL); + res('force exit'); + }, timeout); + + p.once('exit', () => { + clearTimeout(t); + res('exited'); + }); + + p.kill(); + }); +} -- cgit v1.2.3-freya