From df07a713bda4230e8dd38a2b34ef18243d103302 Mon Sep 17 00:00:00 2001 From: Jonas Pfenniger Date: Sat, 24 Apr 2010 22:27:11 +0200 Subject: [PATCH] New test-case: signal unregistration The default signal-handler should be restored if no handlers are assigned. --- test/fixtures/should_exit.js | 6 ++++++ test/pummel/test-signal-unregister.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 test/fixtures/should_exit.js create mode 100644 test/pummel/test-signal-unregister.js diff --git a/test/fixtures/should_exit.js b/test/fixtures/should_exit.js new file mode 100644 index 0000000..826a118 --- /dev/null +++ b/test/fixtures/should_exit.js @@ -0,0 +1,6 @@ +function tmp() {} +process.addListener("SIGINT", tmp); +process.removeListener("SIGINT", tmp); +setInterval(function () { + process.stdout.write('keep alive\n'); +}, 1000); diff --git a/test/pummel/test-signal-unregister.js b/test/pummel/test-signal-unregister.js new file mode 100644 index 0000000..29ce09d --- /dev/null +++ b/test/pummel/test-signal-unregister.js @@ -0,0 +1,31 @@ +require("../common"); + +var childKilled = false, done = false, + spawn = require('child_process').spawn, + sys = require("sys"), + child; + +var join = require('path').join; + +child = spawn(process.argv[0], [join(fixturesDir, 'should_exit.js')]); +child.addListener('exit', function () { + if (!done) childKilled = true; +}); + +setTimeout(function () { + sys.puts("Sending SIGINT"); + child.kill("SIGINT"); + setTimeout(function () { + sys.puts("Chance has been given to die"); + done = true; + if (!childKilled) { + // Cleanup + sys.puts("Child did not die on SIGINT, sending SIGTERM"); + child.kill("SIGTERM"); + } + }, 200); +}, 200); + +process.addListener("exit", function () { + assert.ok(childKilled); +}); -- 2.7.4