mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 19:15:54 +00:00
UT: Clean up and faster tearDown.
This commit is contained in:
@@ -165,6 +165,7 @@ Remote.prototype.connect_helper = function () {
|
|||||||
if (self.expire) {
|
if (self.expire) {
|
||||||
if (self.trace) console.log("remote: was expired");
|
if (self.trace) console.log("remote: was expired");
|
||||||
|
|
||||||
|
ws.onerror = undefined;
|
||||||
self.done(ws.readyState);
|
self.done(ws.readyState);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@@ -300,15 +301,19 @@ Remote.prototype.connect = function (done, timeout) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Target stated is disconnected.
|
// Target stated is disconnected.
|
||||||
|
// Note: if exiting or other side is going away, don't need to disconnect.
|
||||||
Remote.prototype.disconnect = function (done) {
|
Remote.prototype.disconnect = function (done) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var ws = this.ws;
|
var ws = this.ws;
|
||||||
|
|
||||||
|
if (self.trace) console.log("remote: disconnect");
|
||||||
|
|
||||||
ws.onclose = function () {
|
ws.onclose = function () {
|
||||||
if (self.trace) console.log("remote: onclose: %s", ws.readyState);
|
if (self.trace) console.log("remote: onclose: %s", ws.readyState);
|
||||||
done(ws.readyState);
|
done(ws.readyState);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ws package has a hard coded 30 second timeout.
|
||||||
ws.close();
|
ws.close();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ var remote = require("../js/remote.js");
|
|||||||
|
|
||||||
var Amount = amount.Amount;
|
var Amount = amount.Amount;
|
||||||
|
|
||||||
|
var fastTearDown = true;
|
||||||
|
|
||||||
// How long to wait for server to start.
|
// How long to wait for server to start.
|
||||||
var serverDelay = 1500;
|
var serverDelay = 1500;
|
||||||
|
|
||||||
@@ -30,6 +32,14 @@ buster.testCase("Remote functions", {
|
|||||||
|
|
||||||
'tearDown' :
|
'tearDown' :
|
||||||
function (done) {
|
function (done) {
|
||||||
|
if (fastTearDown) {
|
||||||
|
// Fast tearDown
|
||||||
|
server.stop("alpha", function (e) {
|
||||||
|
buster.refute(e);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
alpha.disconnect(function (stat) {
|
alpha.disconnect(function (stat) {
|
||||||
buster.assert(3 == stat); // CLOSED
|
buster.assert(3 == stat); // CLOSED
|
||||||
|
|
||||||
@@ -38,6 +48,7 @@ buster.testCase("Remote functions", {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'request_ledger_current' :
|
'request_ledger_current' :
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ var child = require("child_process");
|
|||||||
var servers = {};
|
var servers = {};
|
||||||
|
|
||||||
// Create a server object
|
// Create a server object
|
||||||
var Server = function(name) {
|
var Server = function (name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -69,16 +69,15 @@ Server.prototype.serverSpawnSync = function() {
|
|||||||
// If regular exit: code=0, signal=null
|
// If regular exit: code=0, signal=null
|
||||||
console.log("server: spawn: server exited code=%s: signal=%s", code, signal);
|
console.log("server: spawn: server exited code=%s: signal=%s", code, signal);
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Prepare server's working directory.
|
// Prepare server's working directory.
|
||||||
Server.prototype.makeBase = function(done) {
|
Server.prototype.makeBase = function (done) {
|
||||||
var path = this.serverPath();
|
var path = this.serverPath();
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
// Reset the server directory, build it if needed.
|
// Reset the server directory, build it if needed.
|
||||||
nodeutils.resetPath(path, '0777', function(e) {
|
nodeutils.resetPath(path, '0777', function (e) {
|
||||||
if (e) {
|
if (e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
@@ -90,10 +89,10 @@ Server.prototype.makeBase = function(done) {
|
|||||||
|
|
||||||
// Create a standalone server.
|
// Create a standalone server.
|
||||||
// Prepare the working directory and spawn the server.
|
// Prepare the working directory and spawn the server.
|
||||||
Server.prototype.start = function(done) {
|
Server.prototype.start = function (done) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.makeBase(function(e) {
|
this.makeBase(function (e) {
|
||||||
if (e) {
|
if (e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
@@ -105,10 +104,10 @@ Server.prototype.start = function(done) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Stop a standalone server.
|
// Stop a standalone server.
|
||||||
Server.prototype.stop = function(done) {
|
Server.prototype.stop = function (done) {
|
||||||
if (this.child) {
|
if (this.child) {
|
||||||
// Update the on exit to invoke done.
|
// Update the on exit to invoke done.
|
||||||
this.child.on('exit', function(code, signal) {
|
this.child.on('exit', function (code, signal) {
|
||||||
console.log("server: stop: server exited");
|
console.log("server: stop: server exited");
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -122,7 +121,7 @@ Server.prototype.stop = function(done) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Start the named server.
|
// Start the named server.
|
||||||
exports.start = function(name, done) {
|
exports.start = function (name, done) {
|
||||||
if (servers[name])
|
if (servers[name])
|
||||||
{
|
{
|
||||||
console.log("server: start: server already started.");
|
console.log("server: start: server already started.");
|
||||||
@@ -140,7 +139,7 @@ exports.start = function(name, done) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Delete the named server.
|
// Delete the named server.
|
||||||
exports.stop = function(name, done) {
|
exports.stop = function (name, done) {
|
||||||
console.log("server: stop: %s of %s", name, Object.keys(servers).toString());
|
console.log("server: stop: %s of %s", name, Object.keys(servers).toString());
|
||||||
|
|
||||||
var server = servers[name];
|
var server = servers[name];
|
||||||
|
|||||||
@@ -30,15 +30,17 @@ buster.testCase("WebSocket connection", {
|
|||||||
|
|
||||||
"websocket connect and disconnect" :
|
"websocket connect and disconnect" :
|
||||||
function (done) {
|
function (done) {
|
||||||
var alpha = remote.remoteConfig(config, "alpha");
|
var alpha = remote.remoteConfig(config, "alpha", 'TRACE');
|
||||||
|
|
||||||
alpha.connect(function (stat) {
|
alpha.connect(function (stat) {
|
||||||
buster.assert(1 == stat); // OPEN
|
buster.assert.equals(stat, 1); // OPEN
|
||||||
|
|
||||||
alpha.disconnect(function (stat) {
|
alpha.disconnect(function (stat) {
|
||||||
buster.assert(3 == stat); // CLOSED
|
buster.assert.equals(stat, 3); // CLOSED
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
}, serverDelay);
|
}, serverDelay);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// vim:sw=2:sts=2:ts=8
|
||||||
|
|||||||
Reference in New Issue
Block a user