From 206ecd088f1bc2bb33c15c3f8c134fe2d8b4f39e Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Mon, 16 Mar 2020 08:51:25 -0600 Subject: [PATCH] fix: regression in `agoric start --reset` Also add integration test for this problem. --- packages/agoric-cli/lib/start.js | 2 +- packages/agoric-cli/test/test-workflow.js | 36 ++++++++++++++++------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/packages/agoric-cli/lib/start.js b/packages/agoric-cli/lib/start.js index 5a025f6202c..510b0b43429 100644 --- a/packages/agoric-cli/lib/start.js +++ b/packages/agoric-cli/lib/start.js @@ -13,7 +13,7 @@ export default async function startMain(progname, rawArgs, powers, opts) { const { anylogger, fs, spawn, os, process } = powers; const log = anylogger('agoric:start'); - const pspawn = (cmd, cargs, { stdio = 'inherit', ...rest }) => { + const pspawn = (cmd, cargs, { stdio = 'inherit', ...rest } = {}) => { log.info(chalk.blueBright(cmd, ...cargs)); return new Promise((resolve, _reject) => { const cp = spawn(cmd, cargs, { stdio, ...rest }); diff --git a/packages/agoric-cli/test/test-workflow.js b/packages/agoric-cli/test/test-workflow.js index b8cc5e86749..d3aa3472630 100644 --- a/packages/agoric-cli/test/test-workflow.js +++ b/packages/agoric-cli/test/test-workflow.js @@ -3,16 +3,18 @@ import fs from 'fs'; import tmp from 'tmp'; import { spawn } from 'child_process'; -import main from '../lib/main'; test('workflow', async t => { try { - const pspawn = (...args) => - new Promise((resolve, _reject) => { - const cp = spawn(...args); + const pspawn = (...args) => { + const cp = spawn(...args); + const pr = new Promise((resolve, _reject) => { cp.on('exit', resolve); cp.on('error', () => resolve(-1)); }); + pr.cp = cp; + return pr; + }; // Run all main programs with the '--sdk' flag if we are in agoric-sdk. const extraArgs = fs.existsSync(`${__dirname}/../../cosmic-swingset`) @@ -21,9 +23,7 @@ test('workflow', async t => { const myMain = args => { console.error('running agoric-cli', ...extraArgs, ...args); return pspawn(`${__dirname}/../bin/agoric`, [...extraArgs, ...args], { - // TODO: make stdio more sane. - // stdio: ['ignore', 'pipe', 'pipe'], - stdio: 'inherit', + stdio: ['ignore', 'pipe', 'inherit'], }); }; @@ -37,11 +37,25 @@ test('workflow', async t => { t.equals(await myMain(['init', 'dapp-foo']), 0, 'init dapp-foo works'); process.chdir('dapp-foo'); - // t.equals(await myMain(['install']), 0, 'install works'); - // It would be nice to test the 'dev' environment with a - // "terminate for upgrade" flag instead of just --no-restart. - t.equals(await myMain(['start', '--no-restart']), 0, 'start works'); + + const startP = myMain(['start', '--reset']); + const to = setTimeout(() => startP.cp.kill('SIGHUP'), 10000); + let stdoutStr = ''; + let successfulStart = false; + startP.cp.stdout.on('data', chunk => { + // console.log('stdout:', chunk.toString()); + stdoutStr += chunk.toString(); + if (stdoutStr.includes('HTTP/WebSocket will listen on')) { + successfulStart = true; + startP.cp.kill('SIGHUP'); + clearTimeout(to); + } + }); + + await startP; + clearTimeout(to); + t.assert(successfulStart, 'start works'); } finally { process.chdir(olddir); removeCallback();