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

45 lines
1.2 KiB
JavaScript
Raw Normal View History

2015-02-02 16:30:05 +01: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 19:38:36 +01:00
var path = require("path");
var child = require("child_process");
2015-02-06 19:10:50 +01:00
function spawn(name) {
var p = child.spawn("node", [path.join(__dirname, name)]);
2015-02-06 14:04:17 +01:00
p.stdout.on("data", function(data) {
2015-02-06 19:10:50 +01:00
console.log("Info from " + name + ": " + data.toString().trim());
2015-02-06 14:04:17 +01:00
});
2015-02-05 19:38:36 +01:00
p.stderr.on("data", function(err) {
2015-02-06 19:10:50 +01:00
console.log("Error from " + name + ": " + err.toString().trim());
2015-02-05 19:38:36 +01:00
});
return p;
}
2015-02-02 16:30:05 +01:00
module.exports = function() {
2015-02-05 19:38:36 +01: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);
}
2015-02-05 20:55:36 +01:00
if (err && err.stack) console.log(err.stack);
2015-02-05 19:38:36 +01:00
if (doExit) process.exit(1);
};
}
process.on("exit", cleanup());
process.on("SIGINT", cleanup(true));
process.on("uncaughtException", cleanup(true));
2015-02-06 19:10:50 +01:00
var tcpNode = spawn("tcp-node.js");
var wsNode = spawn("ws-node.js");
2015-02-02 16:30:05 +01:00
};