bitmessage-js/tests/run-test-nodes.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2015-02-02 15:30:05 +00:00
// Run test nodes for all known transports so we can test library in
// functional test suites. Stop nodes when testing is complete.
// Note that this file is executed only on Node.js platform.
2015-02-05 18:38:36 +00:00
var path = require("path");
var child = require("child_process");
var TCP_NODE_PATH = path.join(__dirname, "tcp-node.js");
var WS_NODE_PATH = path.join(__dirname, "ws-node.js");
function spawn(path) {
var p = child.spawn("node", [path]);
p.stderr.on("data", function(err) {
console.log("Error from", path, ":", err.toString());
});
return p;
}
2015-02-02 15:30:05 +00:00
module.exports = function() {
2015-02-05 18:38:36 +00:00
function cleanup(doExit) {
return function(err) {
try {
tcpNode.kill("SIGKILL");
} catch(e) {
console.log(e.stack);
}
try {
wsNode.kill("SIGKILL");
} catch(e) {
console.log(e.stack);
}
if (err) console.log(err.stack);
if (doExit) process.exit(1);
};
}
var tcpNode = spawn(TCP_NODE_PATH);
var wsNode = spawn(WS_NODE_PATH);
process.on("exit", cleanup());
process.on("SIGINT", cleanup(true));
process.on("uncaughtException", cleanup(true));
2015-02-02 15:30:05 +00:00
};