Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ steps = [
{ argv = ["vp", "install", "-g", "./long-time-install-package"], continue-on-failure = true },
{ argv = ["long-time-install-package"], continue-on-failure = true },
# snapshot = false: the killed install's partial screen is timing-dependent
# (which spinner frame was live at the 100ms SIGKILL) and ConPTY renders a
# (which spinner frame was live when the kill landed) and ConPTY renders a
# trailing blank line Unix does not; the meaningful outcome is asserted by
# the check-stale-packages step that follows.
{ argv = ["node", "test-reinstall-interrupt.js"], comment = "Reinstall but interrupt", snapshot = false, continue-on-failure = true },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
const { spawn } = require('child_process');
const fs = require('fs');
const path = require('path');

const scopeDir = path.join(process.env.VP_HOME, 'packages', '@scope');
const before = new Set(fs.readdirSync(scopeDir));

const child = spawn('vp', ['install', '-g', './long-time-install-package'], {
stdio: 'inherit',
});

setTimeout(() => {
// A fixed kill delay races vp's startup: on slow runners it can fire before
// the reinstall creates its install dir, leaving nothing stale. Kill as soon
// as the new dir appears; the package's 200ms postinstall keeps the install
// running well past that point.
const poll = setInterval(() => {
let entries;
try {
entries = fs.readdirSync(scopeDir);
} catch {
return;
}
if (entries.some((name) => !before.has(name))) {
clearInterval(poll);
child.kill('SIGKILL');
}
}, 10);

// Bound the wait so a reinstall that dies before creating the dir cannot
// hang the case.
const fallback = setTimeout(() => {
clearInterval(poll);
if (!child.killed) {
child.kill('SIGKILL');
}
}, 100);
}, 10_000);

child.on('close', (code) => {
clearInterval(poll);
clearTimeout(fallback);
process.exit(code);
});
Loading