UT: More work on detecting standalone server exit.

This commit is contained in:
Arthur Britto
2013-01-12 12:48:18 -08:00
parent 3b66a13646
commit 8c5f08ad9b
3 changed files with 30 additions and 5 deletions

View File

@@ -196,6 +196,7 @@ var Remote = function (opts, trace) {
this.local_fee = opts.local_fee; // Locally set fees
this.id = 0;
this.trace = opts.trace || trace;
this._server_fatal = false; // True, if we know server exited.
this._ledger_current_index = undefined;
this._ledger_hash = undefined;
this._ledger_time = undefined;
@@ -289,6 +290,11 @@ Remote.fees = {
'offer' : Amount.from_json("10"),
};
// Inform remote that the remote server is not comming back.
Remote.prototype.server_fatal = function () {
this._server_fatal = true;
};
// Set the emitted state: 'online' or 'offline'
Remote.prototype._set_state = function (state) {
if (this.trace) console.log("remote: set_state: %s", state);
@@ -378,7 +384,12 @@ Remote.prototype._connect_retry = function () {
this.retry_timer = setTimeout(function () {
if (self.trace) console.log("remote: retry");
if (self.online_target) {
if (self._server_fatal) {
// Stop trying to connect.
// nothing();
console.log("FATAL");
}
else if (self.online_target) {
self._connect_start();
}
else {

View File

@@ -98,6 +98,10 @@ Server.prototype._serverSpawnSync = function() {
// By default, just log exits.
this.child.on('exit', function(code, signal) {
if (!self.quiet) console.log("server: spawn: server exited code=%s: signal=%s", code, signal);
self.emit('exited');
// Workaround for
// https://github.com/busterjs/buster/issues/266
if (!self.stopping) {
@@ -108,8 +112,6 @@ Server.prototype._serverSpawnSync = function() {
// If regular exit: code=0, signal=null
// Fail the test if the server has not called "stop".
buster.assert(self.stopping, 'Server died with signal '+signal);
if (!self.quiet) console.log("server: spawn: server exited code=%s: signal=%s", code, signal);
});
};

View File

@@ -90,10 +90,22 @@ var build_setup = function (opts, host) {
function runServerStep(callback) {
if (opts.no_server) return callback();
data.server = Server.from_config(host, !!opts.verbose_server).on('started', callback).start();
data.server = Server
.from_config(host, !!opts.verbose_server)
.on('started', callback)
.on('exited', function () {
// If know the remote, tell it server is gone.
if (self.remote)
self.remote.server_fatal();
})
.start();
},
function connectWebsocketStep(callback) {
self.remote = data.remote = Remote.from_config(host, !!opts.verbose_ws).once('ledger_closed', callback).connect();
self.remote = data.remote =
Remote
.from_config(host, !!opts.verbose_ws)
.once('ledger_closed', callback)
.connect();
}
], done);
};