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