2019-03-03 22:51:52 +00:00
|
|
|
import { exec } from './utils/exec';
|
2019-03-02 15:19:08 +00:00
|
|
|
|
|
|
|
const userSuite = process.argv[2];
|
2019-03-03 22:51:52 +00:00
|
|
|
const command = process.argv[3]; // The command to run once the env is up.
|
2019-03-02 15:19:08 +00:00
|
|
|
|
2019-03-03 22:51:52 +00:00
|
|
|
var { setup, setup_timeout, teardown, teardown_timeout } = require(`../test/suites/${userSuite}/environment`);
|
2019-03-02 15:19:08 +00:00
|
|
|
|
|
|
|
function sleep(ms: number) {
|
|
|
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
|
|
}
|
|
|
|
|
|
|
|
let teardownInProgress = false;
|
|
|
|
|
2019-03-03 22:51:52 +00:00
|
|
|
async function block() {
|
|
|
|
while (true) {
|
|
|
|
await sleep(10000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function blockOrRun(cmd: string | null) {
|
|
|
|
if (cmd) {
|
|
|
|
await exec(cmd);
|
|
|
|
} else {
|
|
|
|
await block();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-02 15:19:08 +00:00
|
|
|
process.on('SIGINT', function() {
|
|
|
|
if (teardownInProgress) return;
|
|
|
|
teardownInProgress = true;
|
2019-03-03 22:51:52 +00:00
|
|
|
|
|
|
|
stop()
|
|
|
|
.then(() => process.exit(0))
|
|
|
|
.catch(() => process.exit(1));
|
2019-03-02 15:19:08 +00:00
|
|
|
});
|
|
|
|
|
2019-03-03 22:51:52 +00:00
|
|
|
async function stop() {
|
|
|
|
const timer = setTimeout(() => {
|
|
|
|
console.error('Teardown timed out...');
|
|
|
|
process.exit(1);
|
|
|
|
}, teardown_timeout);
|
|
|
|
console.log('>>> Tearing down environment <<<');
|
|
|
|
try {
|
|
|
|
await teardown();
|
|
|
|
clearTimeout(timer);
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function start() {
|
2019-04-24 21:52:08 +00:00
|
|
|
const timer = setTimeout(async () => {
|
2019-03-03 22:51:52 +00:00
|
|
|
console.error('Setup timed out...');
|
2019-04-24 21:52:08 +00:00
|
|
|
try {
|
|
|
|
await teardown();
|
|
|
|
} catch(err) {
|
|
|
|
process.exit(1)
|
|
|
|
}
|
2019-03-03 22:51:52 +00:00
|
|
|
}, setup_timeout);
|
|
|
|
console.log('>>> Setting up environment <<<');
|
|
|
|
try {
|
|
|
|
await setup();
|
2019-04-24 21:52:08 +00:00
|
|
|
await sleep(200);
|
2019-03-03 22:51:52 +00:00
|
|
|
clearTimeout(timer);
|
|
|
|
await blockOrRun(command);
|
|
|
|
if (!teardownInProgress) {
|
|
|
|
await stop();
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
await stop();
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2019-03-02 15:19:08 +00:00
|
|
|
}
|
|
|
|
|
2019-03-03 22:51:52 +00:00
|
|
|
start();
|