Skip to content

Commit

Permalink
Merge pull request #2593 from Agoric/mfig-2581-cosmic-fixture-cleanup
Browse files Browse the repository at this point in the history
test(cosmic-swingset): more robustness around termination
  • Loading branch information
michaelfig authored Mar 8, 2021
2 parents 840ae0e + 466553b commit ac15f4a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
28 changes: 17 additions & 11 deletions packages/cosmic-swingset/test/captp-fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,35 @@ const PORT = 7999;
// Ensure we're all using the same HandledPromise.
export { E };

export async function makeFixture() {
export async function makeFixture(noisy = false) {
const accessToken = await getAccessToken(PORT);

let expectedToExit = false;
let buf = '';
const stdio = noisy
? ['ignore', 'inherit', 'inherit']
: ['ignore', 'pipe', 'pipe'];
const cp = spawn(
'make',
['scenario3-setup', 'scenario3-run', `BASE_PORT=${PORT}`],
{
cwd: `${__dirname}/..`,
env: { ...process.env, PORT },
stdio: ['ignore', 'pipe', 'pipe'],
stdio,
detached: true,
},
);

cp.stdout.on('data', chunk => (buf += chunk.toString('utf-8')));
cp.stderr.on('data', chunk => {
const msg = chunk.toString('utf-8');
if (!msg.match(/^make: \*\*\*.*99/)) {
// Write chunks that don't describe the exit status.
process.stderr.write(chunk);
}
});
if (!noisy) {
cp.stdout.on('data', chunk => (buf += chunk.toString('utf-8')));
cp.stderr.on('data', chunk => {
const msg = chunk.toString('utf-8');
if (!msg.match(/^make: \*\*\*.*99/)) {
// Write chunks that don't describe the exit status.
process.stderr.write(chunk);
}
});
}

/** @type {WebSocket} */
let ws;
Expand Down Expand Up @@ -122,10 +127,11 @@ export async function makeFixture() {
// Don't kill on exit anymore, as we're doing it now.
process.off('exit', kill);
// console.log('killing!');
process.kill(-cp.pid, 'SIGINT');
process.kill(-cp.pid, 'SIGTERM');
}

process.on('exit', kill);
process.on('SIGINT', kill);
process.on('SIGTERM', kill);
return { homeP: connect(), kill };
}
2 changes: 1 addition & 1 deletion packages/cosmic-swingset/test/test-home.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { makeFixture, E } from './captp-fixture';
let home;
let teardown;
test.before('setup', async t => {
const { homeP, kill } = await makeFixture();
const { homeP, kill } = await makeFixture(process.env.NOISY);
teardown = kill;
home = await homeP;
t.truthy('ready');
Expand Down

0 comments on commit ac15f4a

Please sign in to comment.