mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 02:55:50 +00:00
JS Tests: Refactored config handling.
Still far from perfect, but better than it was.
This commit is contained in:
@@ -7,11 +7,13 @@ var testconfig = require("./testconfig.js");
|
|||||||
|
|
||||||
exports.accounts = testconfig.accounts;
|
exports.accounts = testconfig.accounts;
|
||||||
|
|
||||||
// Where to find the binary.
|
|
||||||
exports.rippled = path.resolve("build/rippled");
|
|
||||||
|
|
||||||
exports.server_default = "alpha";
|
exports.server_default = "alpha";
|
||||||
|
|
||||||
|
exports.default_server_config = {
|
||||||
|
// Where to find the binary.
|
||||||
|
rippled_path: path.resolve(__dirname, "../build/rippled")
|
||||||
|
};
|
||||||
|
|
||||||
//
|
//
|
||||||
// Configuration for servers.
|
// Configuration for servers.
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
var buster = require("buster");
|
var buster = require("buster");
|
||||||
|
var extend = require("extend");
|
||||||
|
var Server = require("./server").Server;
|
||||||
|
|
||||||
var testutils = require("./testutils");
|
var testutils = require("./testutils");
|
||||||
var Server = require("./server").Server;
|
var config = testutils.init_config();
|
||||||
|
|
||||||
// How long to wait for server to start.
|
// How long to wait for server to start.
|
||||||
// var serverDelay = 1500;
|
// var serverDelay = 1500;
|
||||||
@@ -9,19 +12,22 @@ var alpha;
|
|||||||
|
|
||||||
buster.testCase("Standalone server startup", {
|
buster.testCase("Standalone server startup", {
|
||||||
"server start and stop" : function (done) {
|
"server start and stop" : function (done) {
|
||||||
alpha = Server.from_config("alpha", false); //ADD ,true for verbosity
|
var cfg = extend({}, config.default_server_config,
|
||||||
|
config.servers.alpha);
|
||||||
|
|
||||||
alpha
|
alpha = Server.from_config("alpha", cfg);
|
||||||
.on('started', function () {
|
|
||||||
alpha
|
|
||||||
.on('stopped', function () {
|
|
||||||
buster.assert(true);
|
|
||||||
|
|
||||||
done();
|
alpha
|
||||||
})
|
.on('started', function () {
|
||||||
.stop();
|
alpha
|
||||||
|
.on('stopped', function () {
|
||||||
|
buster.assert(true);
|
||||||
|
|
||||||
|
done();
|
||||||
})
|
})
|
||||||
.start();
|
.stop();
|
||||||
|
})
|
||||||
|
.start();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ var path = require("path");
|
|||||||
var util = require("util");
|
var util = require("util");
|
||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
|
|
||||||
var config = require("./config");
|
|
||||||
var nodeutils = require("./nodeutils");
|
var nodeutils = require("./nodeutils");
|
||||||
|
|
||||||
// Create a server object
|
// Create a server object
|
||||||
@@ -58,8 +57,8 @@ var Server = function (name, config, verbose) {
|
|||||||
|
|
||||||
util.inherits(Server, EventEmitter);
|
util.inherits(Server, EventEmitter);
|
||||||
|
|
||||||
Server.from_config = function (name, verbose) {
|
Server.from_config = function (name, config, verbose) {
|
||||||
return new Server(name, config.servers[name], verbose);
|
return new Server(name, config, verbose);
|
||||||
};
|
};
|
||||||
|
|
||||||
Server.prototype.on = function (e, c) {
|
Server.prototype.on = function (e, c) {
|
||||||
@@ -106,7 +105,7 @@ Server.prototype._serverSpawnSync = function() {
|
|||||||
|
|
||||||
// Spawn in standalone mode for now.
|
// Spawn in standalone mode for now.
|
||||||
this.child = child.spawn(
|
this.child = child.spawn(
|
||||||
config.rippled,
|
this.config.rippled_path,
|
||||||
args,
|
args,
|
||||||
{
|
{
|
||||||
cwd: this.serverPath(),
|
cwd: this.serverPath(),
|
||||||
@@ -116,7 +115,10 @@ Server.prototype._serverSpawnSync = function() {
|
|||||||
|
|
||||||
if (!this.quiet)
|
if (!this.quiet)
|
||||||
console.log("server: start %s: %s --conf=%s",
|
console.log("server: start %s: %s --conf=%s",
|
||||||
this.child.pid, config.rippled, args.join(" "), this.configPath());
|
this.child.pid,
|
||||||
|
this.config.rippled_path,
|
||||||
|
args.join(" "),
|
||||||
|
this.configPath());
|
||||||
|
|
||||||
// By default, just log exits.
|
// By default, just log exits.
|
||||||
this.child.on('exit', function(code, signal) {
|
this.child.on('exit', function(code, signal) {
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
var async = require("async");
|
var async = require("async");
|
||||||
|
var extend = require("extend");
|
||||||
|
|
||||||
var Amount = require("ripple-lib").Amount;
|
var Amount = require("ripple-lib").Amount;
|
||||||
var Remote = require("ripple-lib").Remote;
|
var Remote = require("ripple-lib").Remote;
|
||||||
var Server = require("./server").Server;
|
var Server = require("./server").Server;
|
||||||
var Transaction = require("ripple-lib").Transaction;
|
var Transaction = require("ripple-lib").Transaction;
|
||||||
|
|
||||||
var config = require('ripple-lib').config.load(require('./config'));
|
|
||||||
|
|
||||||
var account_dump = function (remote, account, callback) {
|
var account_dump = function (remote, account, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
@@ -65,6 +64,8 @@ var account_dump = function (remote, account, callback) {
|
|||||||
* @param host {String} Identifier for the host configuration to be used.
|
* @param host {String} Identifier for the host configuration to be used.
|
||||||
*/
|
*/
|
||||||
var build_setup = function (opts, host) {
|
var build_setup = function (opts, host) {
|
||||||
|
var config = get_config();
|
||||||
|
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
|
||||||
// Normalize options
|
// Normalize options
|
||||||
@@ -100,8 +101,12 @@ var build_setup = function (opts, host) {
|
|||||||
function runServerStep(callback) {
|
function runServerStep(callback) {
|
||||||
if (opts.no_server) return callback();
|
if (opts.no_server) return callback();
|
||||||
|
|
||||||
|
var server_config = extend({}, config.default_server_config,
|
||||||
|
config.servers[host]);
|
||||||
|
|
||||||
data.server = Server
|
data.server = Server
|
||||||
.from_config(host, !!opts.verbose_server)
|
.from_config(host, server_config,
|
||||||
|
!!opts.verbose_server)
|
||||||
.on('started', callback)
|
.on('started', callback)
|
||||||
.on('exited', function () {
|
.on('exited', function () {
|
||||||
// If know the remote, tell it server is gone.
|
// If know the remote, tell it server is gone.
|
||||||
@@ -127,6 +132,7 @@ var build_setup = function (opts, host) {
|
|||||||
* @param host {String} Identifier for the host configuration to be used.
|
* @param host {String} Identifier for the host configuration to be used.
|
||||||
*/
|
*/
|
||||||
var build_teardown = function (host) {
|
var build_teardown = function (host) {
|
||||||
|
var config = get_config();
|
||||||
|
|
||||||
return function (done) {
|
return function (done) {
|
||||||
host = host || config.server_default;
|
host = host || config.server_default;
|
||||||
@@ -218,16 +224,20 @@ var credit_limit = function (remote, src, amount, callback) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function init_config() {
|
function get_config() {
|
||||||
var cfg;
|
var cfg = require('./config-example');
|
||||||
|
|
||||||
// See if the person testing wants to override the configuration by creating a
|
// See if the person testing wants to override the configuration by creating a
|
||||||
// file called test/config.js.
|
// file called test/config.js.
|
||||||
try {
|
try {
|
||||||
cfg = require('./config');
|
cfg = extend({}, cfg, require('./config'));
|
||||||
} catch (e) {
|
} catch (e) { }
|
||||||
cfg = require('./config-example');
|
|
||||||
}
|
return cfg;
|
||||||
|
}
|
||||||
|
|
||||||
|
function init_config() {
|
||||||
|
var cfg = get_config();
|
||||||
|
|
||||||
return require('ripple-lib').config.load(cfg);
|
return require('ripple-lib').config.load(cfg);
|
||||||
}
|
}
|
||||||
@@ -500,6 +510,7 @@ exports.build_teardown = build_teardown;
|
|||||||
exports.create_accounts = create_accounts;
|
exports.create_accounts = create_accounts;
|
||||||
exports.credit_limit = credit_limit;
|
exports.credit_limit = credit_limit;
|
||||||
exports.credit_limits = credit_limits;
|
exports.credit_limits = credit_limits;
|
||||||
|
exports.get_config = get_config;
|
||||||
exports.init_config = init_config;
|
exports.init_config = init_config;
|
||||||
exports.ledger_close = ledger_close;
|
exports.ledger_close = ledger_close;
|
||||||
exports.payment = payment;
|
exports.payment = payment;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
var buster = require("buster");
|
var buster = require("buster");
|
||||||
|
var extend = require("extend");
|
||||||
|
|
||||||
var Server = require("./server").Server;
|
var Server = require("./server").Server;
|
||||||
var Remote = require("ripple-lib").Remote;
|
var Remote = require("ripple-lib").Remote;
|
||||||
@@ -8,12 +9,27 @@ var config = testutils.init_config();
|
|||||||
|
|
||||||
buster.testRunner.timeout = 5000;
|
buster.testRunner.timeout = 5000;
|
||||||
|
|
||||||
|
var server;
|
||||||
buster.testCase("WebSocket connection", {
|
buster.testCase("WebSocket connection", {
|
||||||
'setUp' :
|
'setUp' :
|
||||||
function (done) { if (config.servers.alpha.no_server) done(); else server = Server.from_config("alpha").on('started', done).start(); },
|
function (done) {
|
||||||
|
var cfg = extend({}, config.default_server_config,
|
||||||
|
config.servers.alpha);
|
||||||
|
if (cfg.no_server) {
|
||||||
|
done();
|
||||||
|
} else {
|
||||||
|
server = Server.from_config("alpha", cfg).on('started', done).start();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
'tearDown' :
|
'tearDown' :
|
||||||
function (done) { if (config.servers.alpha.no_server) done(); else server.on('stopped', done).stop(); },
|
function (done) {
|
||||||
|
if (config.servers.alpha.no_server) {
|
||||||
|
done();
|
||||||
|
} else {
|
||||||
|
server.on('stopped', done).stop();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
"websocket connect and disconnect" :
|
"websocket connect and disconnect" :
|
||||||
function (done) {
|
function (done) {
|
||||||
|
|||||||
Reference in New Issue
Block a user