UT: Clean up and faster tearDown.

This commit is contained in:
Arthur Britto
2012-10-14 01:31:46 -07:00
parent 085ff2af22
commit 5fc3d98ef5
5 changed files with 115 additions and 98 deletions

View File

@@ -165,6 +165,7 @@ Remote.prototype.connect_helper = function () {
if (self.expire) {
if (self.trace) console.log("remote: was expired");
ws.onerror = undefined;
self.done(ws.readyState);
} else {
@@ -300,15 +301,19 @@ Remote.prototype.connect = function (done, timeout) {
};
// Target stated is disconnected.
// Note: if exiting or other side is going away, don't need to disconnect.
Remote.prototype.disconnect = function (done) {
var self = this;
var ws = this.ws;
if (self.trace) console.log("remote: disconnect");
ws.onclose = function () {
if (self.trace) console.log("remote: onclose: %s", ws.readyState);
done(ws.readyState);
};
// ws package has a hard coded 30 second timeout.
ws.close();
};

View File

@@ -7,6 +7,8 @@ var remote = require("../js/remote.js");
var Amount = amount.Amount;
var fastTearDown = true;
// How long to wait for server to start.
var serverDelay = 1500;
@@ -30,6 +32,14 @@ buster.testCase("Remote functions", {
'tearDown' :
function (done) {
if (fastTearDown) {
// Fast tearDown
server.stop("alpha", function (e) {
buster.refute(e);
done();
});
}
else {
alpha.disconnect(function (stat) {
buster.assert(3 == stat); // CLOSED
@@ -38,6 +48,7 @@ buster.testCase("Remote functions", {
done();
});
});
}
},
'request_ledger_current' :

View File

@@ -69,7 +69,6 @@ Server.prototype.serverSpawnSync = function() {
// If regular exit: code=0, signal=null
console.log("server: spawn: server exited code=%s: signal=%s", code, signal);
});
};
// Prepare server's working directory.

View File

@@ -30,15 +30,17 @@ buster.testCase("WebSocket connection", {
"websocket connect and disconnect" :
function (done) {
var alpha = remote.remoteConfig(config, "alpha");
var alpha = remote.remoteConfig(config, "alpha", 'TRACE');
alpha.connect(function (stat) {
buster.assert(1 == stat); // OPEN
buster.assert.equals(stat, 1); // OPEN
alpha.disconnect(function (stat) {
buster.assert(3 == stat); // CLOSED
buster.assert.equals(stat, 3); // CLOSED
done();
});
}, serverDelay);
},
});
// vim:sw=2:sts=2:ts=8