Enable logStream test
fixes apptask logs in test mode and the id of stream logs
This commit is contained in:
@@ -397,7 +397,7 @@ function getLogStream(req, res, next) {
|
||||
res.on('close', logStream.close);
|
||||
logStream.on('data', function (data) {
|
||||
var obj = JSON.parse(data);
|
||||
res.write(sse(obj.monotonicTimestamp, JSON.stringify(obj))); // send timestamp as id
|
||||
res.write(sse(obj.realtimeTimestamp, JSON.stringify(obj))); // send timestamp as id
|
||||
});
|
||||
logStream.on('end', res.end.bind(res));
|
||||
logStream.on('error', res.end.bind(res, null));
|
||||
|
||||
@@ -867,7 +867,7 @@ describe('App installation', function () {
|
||||
});
|
||||
});
|
||||
|
||||
xit('logStream - stream logs', function (done) {
|
||||
it('logStream - stream logs', function (done) {
|
||||
var options = {
|
||||
port: config.get('port'), host: 'localhost', path: '/api/v1/apps/' + APP_ID + '/logstream?access_token=' + token,
|
||||
headers: { 'Accept': 'text/event-stream', 'Connection': 'keep-alive' }
|
||||
@@ -876,18 +876,15 @@ describe('App installation', function () {
|
||||
// superagent doesn't work. maybe https://github.com/visionmedia/superagent/issues/420
|
||||
var req = http.get(options, function (res) {
|
||||
var data = '';
|
||||
res.on('data', function (d) { data += d.toString('utf8'); console.log('=== logstream data', d.toString('utf8')); });
|
||||
res.on('data', function (d) { data += d.toString('utf8'); });
|
||||
setTimeout(function checkData() {
|
||||
expect(data.length).to.not.be(0);
|
||||
var lineNumber = 1;
|
||||
data.split('\n').forEach(function (line) {
|
||||
if (line.indexOf('id: ') !== 0) return;
|
||||
expect(parseInt(line.substr(4), 10)).to.be(lineNumber); // line number
|
||||
++lineNumber;
|
||||
expect(parseInt(line.substr(4), 10)).to.be.a('number'); // timestamp
|
||||
});
|
||||
|
||||
req.abort();
|
||||
expect(lineNumber).to.be.above(1);
|
||||
done();
|
||||
}, 1000);
|
||||
res.on('error', done);
|
||||
|
||||
@@ -142,8 +142,11 @@ function startAppTask(appId, callback) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
// when running tests, we have to inject the DEBUG env. in cloudron, the value is inherited
|
||||
const env = process.env.BOX_ENV === 'test' ? _.extend({}, process.env, { DEBUG: 'box*,connect-lastmile' }) : process.env;
|
||||
|
||||
// when parent process dies, apptask processes are killed because KillMode=control-group in systemd unit file
|
||||
gActiveTasks[appId] = child_process.fork(__dirname + '/apptask.js', [ appId ], { stdio: [ 'pipe', fd, fd, 'ipc' ]});
|
||||
gActiveTasks[appId] = child_process.fork(__dirname + '/apptask.js', [ appId ], { stdio: [ 'pipe', fd, fd, 'ipc' ], env: env });
|
||||
|
||||
var pid = gActiveTasks[appId].pid;
|
||||
debug('Started task of %s pid: %s. See logs at %s', appId, pid, logFilePath);
|
||||
|
||||
Reference in New Issue
Block a user