Skip to content
Myr

feature: support for signals to subcommands (#632)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* add basic subcommand signal tests and fixture These tests verify that a signal sent to the process is correctly propagated to the subcommand * add propagation of supported signals to subcommands Choice of supported signals: https://nodejs.org/api/process.html#process_signal_events * increase timeout for subcommand signal handling for better success rate * increase timeout for subcommand spawn for better success rate in tests * make pm-listen fixture executable * finetune SIGUSR1 test for possible warning from node

authored by Thomas Simoens · committed by Tomoaki Abe · parent 3c2fd5c · Browse files · 8 files+158 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

8 files+158 added−0 removed

  • tests:+150 added−0 removed
  • other:+8 added−0 removed

8 files+158 added−0 removed

modified:test/fixtures/pm+1 added
6 unmodified lines
7 .command('install [name]', 'install one or more packages').alias('i')8 .command('search [query]', 'search with optional query').alias('s')9 .command('cache', 'actions dealing with the cache').alias('c')10 .command('list', 'list packages installed')11 .command('listen', 'listen for supported signal events').alias('l')12 .command('publish', 'publish or update package').alias('p')13 .command('default', 'default command', {noHelp: true, isDefault: true})14 .parse(process.argv);
added:test/fixtures/pm-listen+28 added
1#!/usr/bin/env node23process.on('SIGUSR1', function(){4 console.log('SIGUSR1');5 process.exit();6});78process.on('SIGUSR2', function(){9 console.log('SIGUSR2');10 process.exit();11});1213process.on('SIGTERM', function(){14 console.log('SIGTERM');15 process.exit();16});1718process.on('SIGINT', function(){19 console.log('SIGINT');20 process.exit();21});2223process.on('SIGHUP', function(){24 console.log('SIGHUP');25 process.exit();26});2728setInterval(function(){}, 5000); // Mimic a running process
added:test/test.command.executableSubcommand.signals.hup.js+22 added
added:test/test.command.executableSubcommand.signals.int.js+22 added
added:test/test.command.executableSubcommand.signals.term.js+22 added
added:test/test.command.executableSubcommand.signals.usr1.js+33 added
added:test/test.command.executableSubcommand.signals.usr2.js+22 added
modified:index.js+8 added
548 unmodified lines
549 args.unshift(bin);550 proc = spawn(process.execPath, args, { stdio: 'inherit'});551 }552553 var signals = ['SIGUSR1', 'SIGUSR2', 'SIGTERM', 'SIGINT', 'SIGHUP'];554 signals.forEach(function(signal) {555 process.on(signal, function(){556 if ((proc.killed === false) && (proc.exitCode === null)){557 proc.kill(signal);558 }559 });560 });561 proc.on('close', process.exit.bind(process));562 proc.on('error', function(err) {563 if (err.code == "ENOENT") {564 console.error('\n %s(1) does not exist, try --help\n', bin);
573 unmodified lines