Wait shutdown in test

This commit is contained in:
mei23
2021-06-04 20:56:19 +09:00
parent 79c33ab536
commit 8a9f736cde
6 changed files with 32 additions and 15 deletions

View File

@@ -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();
});
}