Skip to content

Commit

Permalink
Avoid osrm-routed shutdown in After hook
Browse files Browse the repository at this point in the history
  • Loading branch information
oxidase committed Sep 5, 2016
1 parent 29e8aa3 commit 6fbfdf1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
7 changes: 5 additions & 2 deletions features/lib/osrm_loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ class OSRMDatastoreLoader extends OSRMBaseLoader {

this.loadData((err) => {
if (err) return callback(err);
if (this.osrmIsRunning()) return callback();
else this.launch(callback);
if (!this.osrmIsRunning()) this.launch(callback);
else {
this.scope.setupOutputLog(this.child, fs.createWriteStream(this.scope.scenarioLogFile, {'flags': 'a'}));
callback();
}
});
}

Expand Down
9 changes: 4 additions & 5 deletions features/support/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var d3 = require('d3-queue');
var path = require('path');
var mkdirp = require('mkdirp');
var rimraf = require('rimraf');
var OSM = require('../lib/osm');
var OSRMLoader = require('../lib/osrm_loader');

Expand Down Expand Up @@ -45,15 +46,13 @@ module.exports = function () {
this.scenarioLogFile = path.join(logDir, this.scenarioID) + '.log';
d3.queue(1)
.defer(mkdirp, logDir)
.defer(rimraf, this.scenarioLogFile)
.awaitAll(callback);
});

this.After((scenario, callback) => {
var that = this;
this.osrmLoader.shutdown(function() {
that.resetOptionsOutput();
callback();
});
this.resetOptionsOutput();
callback();
});

this.AfterFeatures((features, callback) => {
Expand Down
17 changes: 13 additions & 4 deletions features/support/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ module.exports = function () {
return opts;
};

this.setupOutputLog = (process, log) => {
if (process.logFunc) {
process.stdout.removeListener('data', process.logFunc);
process.stderr.removeListener('data', process.logFunc);
}

process.logFunc = (message) => { log.write(message); };
process.stdout.on('data', process.logFunc);
process.stderr.on('data', process.logFunc);
};

this.runBin = (bin, options, env, callback) => {
let cmd = util.format('%s%s/%s%s%s', this.QQ, this.BIN_PATH, bin, this.EXE, this.QQ);
let opts = options.split(' ').filter((x) => { return x && x.length > 0; });
Expand All @@ -32,12 +43,10 @@ module.exports = function () {
// we need to set a large maxbuffer here because we have long running processes like osrm-routed
// with lots of log output
let child = child_process.execFile(cmd, opts, {maxBuffer: 1024 * 1024 * 1000, env: env}, callback);
child.stdout.on('data', (message) => { log.write(message); });
child.stderr.on('data', (message) => { log.write(message); });
child.on('exit', function(code) {
log.write(util.format('*** %s exited with code %d\n', bin, code));
log.end();
log.end(util.format('*** %s exited with code %d\n', bin, code));
}.bind(this));
this.setupOutputLog(child, log);
return child;
};
};

0 comments on commit 6fbfdf1

Please sign in to comment.