UT: Fixed host configurations and having multiple instances of test suite.

This commit is contained in:
Stefan Thomas
2012-10-24 09:35:31 +02:00
parent 5684a8e233
commit bbec036837
4 changed files with 36 additions and 27 deletions

View File

@@ -12,7 +12,7 @@ buster.testRunner.timeout = 5000;
buster.testCase("Offer tests", { buster.testCase("Offer tests", {
'setUp' : testutils.build_setup(), 'setUp' : testutils.build_setup(),
'tearDown' : testutils.test_teardown, 'tearDown' : testutils.build_teardown(),
"offer create then cancel in one ledger" : "offer create then cancel in one ledger" :
function (done) { function (done) {

View File

@@ -15,7 +15,7 @@ buster.testRunner.timeout = 5000;
buster.testCase("Remote functions", { buster.testCase("Remote functions", {
'setUp' : testutils.build_setup(), 'setUp' : testutils.build_setup(),
'tearDown' : testutils.test_teardown, 'tearDown' : testutils.build_teardown(),
'request_ledger_current' : 'request_ledger_current' :
function (done) { function (done) {

View File

@@ -14,7 +14,7 @@ buster.testRunner.timeout = 5000;
buster.testCase("// Sending", { buster.testCase("// Sending", {
'setUp' : testutils.build_setup(), 'setUp' : testutils.build_setup(),
'tearDown' : testutils.test_teardown, 'tearDown' : testutils.build_teardown(),
"send XNS to non-existant account without create." : "send XNS to non-existant account without create." :
function (done) { function (done) {
@@ -236,7 +236,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.build_setup(), 'setUp' : testutils.build_setup(),
'tearDown' : testutils.test_teardown, 'tearDown' : testutils.build_teardown(),
"direct ripple" : "direct ripple" :
function (done) { function (done) {

View File

@@ -19,7 +19,6 @@ var config = require("./config.js");
* // ... * // ...
* }); * });
* *
* @param host {String} Identifier for the host configuration to be used.
* @param opts {Object} These options allow quick-and-dirty test-specific * @param opts {Object} These options allow quick-and-dirty test-specific
* customizations of your test environment. * customizations of your test environment.
* @param opts.verbose {Bool} Enable all debug output (then cover your ears * @param opts.verbose {Bool} Enable all debug output (then cover your ears
@@ -28,9 +27,10 @@ var config = require("./config.js");
* websocket traffic. * websocket traffic.
* @param opts.verbose_server {Bool} Set the -v option when running rippled. * @param opts.verbose_server {Bool} Set the -v option when running rippled.
* @param opts.no_server {Bool} Don't auto-run rippled. * @param opts.no_server {Bool} Don't auto-run rippled.
* @param host {String} Identifier for the host configuration to be used.
*/ */
var build_setup = function (opts) { var build_setup = function (opts, host) {
opts = this.opts = opts || {}; opts = opts || {};
// Normalize options // Normalize options
if (opts.verbose) { if (opts.verbose) {
@@ -41,12 +41,14 @@ var build_setup = function (opts) {
return function (done) { return function (done) {
var self = this; var self = this;
var host = host || config.server_default; host = host || config.server_default;
this.store = this.store || {}; this.store = this.store || {};
var data = this.store[host] = this.store[host] || {}; var data = this.store[host] = this.store[host] || {};
data.opts = opts;
async.series([ async.series([
function runServerStep(callback) { function runServerStep(callback) {
if (opts.no_server) return callback(); if (opts.no_server) return callback();
@@ -60,24 +62,31 @@ var build_setup = function (opts) {
}; };
}; };
var test_teardown = function (done, host) { /**
host = host || config.server_default; * Generate tearDown routine.
*
* @param host {String} Identifier for the host configuration to be used.
*/
var build_teardown = function (host) {
return function (done) {
host = host || config.server_default;
var data = this.store[host]; var data = this.store[host];
var opts = this.opts; var opts = data.opts;
async.series([ async.series([
function disconnectWebsocketStep(callback) { function disconnectWebsocketStep(callback) {
data.remote data.remote
.on('disconnected', callback) .on('disconnected', callback)
.connect(false); .connect(false);
}, },
function stopServerStep(callback) { function stopServerStep(callback) {
if (opts.no_server) return callback(); if (opts.no_server) return callback();
data.server.on('stopped', callback).stop(); data.server.on('stopped', callback).stop();
} }
], done); ], done);
};
}; };
var create_accounts = function (remote, src, amount, accounts, callback) { var create_accounts = function (remote, src, amount, accounts, callback) {
@@ -119,9 +128,9 @@ var credit_limit = function (remote, src, amount, callback) {
.submit(); .submit();
}; };
exports.create_accounts = create_accounts; exports.create_accounts = create_accounts;
exports.credit_limit = credit_limit; exports.credit_limit = credit_limit;
exports.build_setup = build_setup; exports.build_setup = build_setup;
exports.test_teardown = test_teardown; exports.build_teardown = build_teardown;
// vim:sw=2:sts=2:ts=8 // vim:sw=2:sts=2:ts=8