Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(cosmic-swingset): more robustness around termination #2593

Merged
merged 2 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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