mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
UT: Added verbosity and no_server options to setUp routine.
This commit is contained in:
@@ -11,7 +11,7 @@ var testutils = require("./testutils.js");
|
|||||||
buster.testRunner.timeout = 5000;
|
buster.testRunner.timeout = 5000;
|
||||||
|
|
||||||
buster.testCase("Offer tests", {
|
buster.testCase("Offer tests", {
|
||||||
'setUp' : testutils.test_setup,
|
'setUp' : testutils.build_setup(),
|
||||||
'tearDown' : testutils.test_teardown,
|
'tearDown' : testutils.test_teardown,
|
||||||
|
|
||||||
"offer create then cancel in one ledger" :
|
"offer create then cancel in one ledger" :
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ var serverDelay = 1500; // XXX Not implemented.
|
|||||||
buster.testRunner.timeout = 5000;
|
buster.testRunner.timeout = 5000;
|
||||||
|
|
||||||
buster.testCase("Remote functions", {
|
buster.testCase("Remote functions", {
|
||||||
'setUp' : testutils.test_setup,
|
'setUp' : testutils.build_setup(),
|
||||||
'tearDown' : testutils.test_teardown,
|
'tearDown' : testutils.test_teardown,
|
||||||
|
|
||||||
'request_ledger_current' :
|
'request_ledger_current' :
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ var serverDelay = 1500;
|
|||||||
buster.testRunner.timeout = 5000;
|
buster.testRunner.timeout = 5000;
|
||||||
|
|
||||||
buster.testCase("// Sending", {
|
buster.testCase("// Sending", {
|
||||||
'setUp' : testutils.test_setup,
|
'setUp' : testutils.build_setup(),
|
||||||
'tearDown' : testutils.test_teardown,
|
'tearDown' : testutils.test_teardown,
|
||||||
|
|
||||||
"send XNS to non-existant account without create." :
|
"send XNS to non-existant account without create." :
|
||||||
@@ -235,7 +235,7 @@ buster.testCase("// Sending", {
|
|||||||
|
|
||||||
// XXX In the future add ledger_accept after partial retry is implemented in the server.
|
// XXX In the future add ledger_accept after partial retry is implemented in the server.
|
||||||
buster.testCase("Sending future", {
|
buster.testCase("Sending future", {
|
||||||
'setUp' : testutils.test_setup,
|
'setUp' : testutils.build_setup(),
|
||||||
'tearDown' : testutils.test_teardown,
|
'tearDown' : testutils.test_teardown,
|
||||||
|
|
||||||
"direct ripple" :
|
"direct ripple" :
|
||||||
|
|||||||
@@ -6,33 +6,78 @@ var Server = require("./server.js").Server;
|
|||||||
|
|
||||||
var config = require("./config.js");
|
var config = require("./config.js");
|
||||||
|
|
||||||
var test_setup = function (done, host, verbose) {
|
/**
|
||||||
var self = this;
|
* Helper called by test cases to generate a setUp routine.
|
||||||
var host = host || config.server_default;
|
*
|
||||||
|
* By default you would call this without options, but it is useful to
|
||||||
|
* be able to plug options in during development for quick and easy
|
||||||
|
* debugging.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* buster.testCase("Foobar", {
|
||||||
|
* setUp: testutils.build_setup({verbose: true}),
|
||||||
|
* // ...
|
||||||
|
* });
|
||||||
|
*
|
||||||
|
* @param host {String} Identifier for the host configuration to be used.
|
||||||
|
* @param opts {Object} These options allow quick-and-dirty test-specific
|
||||||
|
* customizations of your test environment.
|
||||||
|
* @param opts.verbose {Bool} Enable all debug output (then cover your ears
|
||||||
|
* and run)
|
||||||
|
* @param opts.verbose_ws {Bool} Enable tracing in the Remote class. Prints
|
||||||
|
* websocket traffic.
|
||||||
|
* @param opts.verbose_server {Bool} Set the -v option when running rippled.
|
||||||
|
* @param opts.no_server {Bool} Don't auto-run rippled.
|
||||||
|
*/
|
||||||
|
var build_setup = function (opts) {
|
||||||
|
opts = this.opts = opts || {};
|
||||||
|
|
||||||
this.store = this.store || {};
|
// Normalize options
|
||||||
|
if (opts.verbose) {
|
||||||
|
opts.verbose_ws = true;
|
||||||
|
opts.verbose_server = true;
|
||||||
|
};
|
||||||
|
|
||||||
var data = this.store[host] = this.store[host] || {};
|
return function (done) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
data.server = Server.from_config(host, verbose).on('started', function () {
|
var host = host || config.server_default;
|
||||||
self.remote = data.remote = Remote.from_config(host).once('ledger_closed', done).connect();
|
|
||||||
}).start();
|
this.store = this.store || {};
|
||||||
|
|
||||||
|
var data = this.store[host] = this.store[host] || {};
|
||||||
|
|
||||||
|
async.series([
|
||||||
|
function runServerStep(callback) {
|
||||||
|
if (opts.no_server) return callback();
|
||||||
|
|
||||||
|
data.server = Server.from_config(host, !!opts.verbose_server).on('started', callback).start();
|
||||||
|
},
|
||||||
|
function connectWebsocketStep(callback) {
|
||||||
|
self.remote = data.remote = Remote.from_config(host, !!opts.verbose_ws).once('ledger_closed', callback).connect();
|
||||||
|
}
|
||||||
|
], done);
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var test_setup_verbose = function (done, host) {
|
var test_teardown = function (done, host) {
|
||||||
test_setup.call(this, done, host, 'VERBOSE');
|
host = host || config.server_default;
|
||||||
}
|
|
||||||
|
|
||||||
var test_teardown = function (done, host) {
|
var data = this.store[host];
|
||||||
var host = host || config.server_default;
|
var opts = this.opts;
|
||||||
|
|
||||||
var data = this.store[host];
|
async.series([
|
||||||
|
function disconnectWebsocketStep(callback) {
|
||||||
|
data.remote
|
||||||
|
.on('disconnected', callback)
|
||||||
|
.connect(false);
|
||||||
|
},
|
||||||
|
function stopServerStep(callback) {
|
||||||
|
if (opts.no_server) return callback();
|
||||||
|
|
||||||
data.remote
|
data.server.on('stopped', callback).stop();
|
||||||
.on('disconnected', function () {
|
}
|
||||||
data.server.on('stopped', done).stop();
|
], done);
|
||||||
})
|
|
||||||
.connect(false);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var create_accounts = function (remote, src, amount, accounts, callback) {
|
var create_accounts = function (remote, src, amount, accounts, callback) {
|
||||||
@@ -76,8 +121,7 @@ var credit_limit = function (remote, src, amount, callback) {
|
|||||||
|
|
||||||
exports.create_accounts = create_accounts;
|
exports.create_accounts = create_accounts;
|
||||||
exports.credit_limit = credit_limit;
|
exports.credit_limit = credit_limit;
|
||||||
exports.test_setup = test_setup;
|
exports.build_setup = build_setup;
|
||||||
exports.test_setup_verbose = test_setup_verbose;
|
|
||||||
exports.test_teardown = test_teardown;
|
exports.test_teardown = test_teardown;
|
||||||
|
|
||||||
// vim:sw=2:sts=2:ts=8
|
// vim:sw=2:sts=2:ts=8
|
||||||
|
|||||||
Reference in New Issue
Block a user