Пример #1
0
    function runTests(options) {
      var scenarioIndex = 0;
      var outputReader;
      var jsonReader;

      console.log(color("\n------------------------------------------------------------", "black+white_bg"));
      console.log(color("Running cucumber" + (options.dryRun ? " dry run " : " ") + "feature path :-\n  " + options.run, "yellow+bold"));
      console.log(color("JSON output path :-\n  " + options.output, "yellow+bold"));
      console.log(color("\n------------------------------------------------------------", "black+white_bg"));

      if (options.scenarioCount) {
        outputReader = growingFile.open(options.output, { timeout: Infinity, interval: 250 });
        jsonReader = jsonStream.parse("*.elements.*");
        outputReader.pipe(jsonReader);

        jsonReader.on("data", function (data) {
          scenarioIndex++;

          var scenarioStatus = "passed";

          if (data.steps) {
            data.steps.forEach(function (step) {
              if (step.result) {
                if (scenarioStatus === "passed" && step.result.status !== "passed") {
                  scenarioStatus = "failed";
                }
              }
            });
          }

          runningSocket.emit("testsProgressed", { percent: Math.round((scenarioIndex / options.scenarioCount) * 100), scenarioStatus: scenarioStatus });
        });
        
        jsonReader.on('root', function(root, count) {
          jsonReader.destroy();
          jsonReader = null;
          outputReader.destroy();
          outputReader = null;
        });        
      }

      var start = new Date();

      ctContext.behaviours.report_core.runTests(ce.cloneextend(ctContext, {
        output: options.output, //cukeTree input (report.json)
        run: options.run,
        dryRun: options.dryRun
      }), function (code) {
        var elapsed = (new Date() - start) / 1000;

        if (options.finishedCallback) {
          options.finishedCallback(code);
        }
        else {
          cucumberProcessFinished(code, options.output, elapsed)
        }
      });
    }
Пример #2
0
routes.buildLog = function(req, res, next) {
  var logFile = path.join(utils.path('logs'), req.params.build + '.log');

  if (fs.existsSync(logFile)) {
    res.writeHead(200, {'Content-Type': 'text/plain'});

    growingFile.open(logFile, {timeout: 60000, interval: 1000}).pipe(res);
    return;
  }

  res.status(404);
  next();
};
Пример #3
0
  mongoQLog.findOne().select('timestamp').sort('-LAST_MOD').exec(function (err, timestamp) {
    if (err) throw err;
    timestamp = timestamp || 0;

    var GrowingFile = require('growing-file');

    var milliseconds = 1000 // Milliseconds in one second
      , seconds      = 60   // Second in one minute
      , minutes      = 60   // Minutes in one hour
      , hours        = 24   // Hours in one day
      , days         = 7;   // Days in one week

    // Timeout is a week, can be changed.
    var timeout      = days * hours * minutes * seconds * milliseconds;

    var firstReading = true;
    var qlogFile = '/var/log/asterisk/queue_log';
    var file = GrowingFile.open(qlogFile, { "timeout": timeout });

    file.on('data', function (data) {
      if (firstReading) {
        firstReading = false;

        var Lines = (data.toString('utf-8').trim().split('\n'));
        for (var i = 0; i < Lines.length; i++) {
          var Line = JSONLine(Lines[i].split('|'));
          if (Line.timestamp > timestamp) {
            new mongoQLog(Line).save();
          } else if (Line.timestamp == timestamp) {
            mongoQLog.findOne(Line, function (err, qlog) {
              if (err) throw err;
              if (!qlog) new mongoQLog(Line).save();
            });
          }
        }
      } else {
        var Line = JSONLine(data.toString('utf-8').trim().split('|'));
        new mongoQLog(Line).save();
      }
    });
  });
Пример #4
0
server = http.createServer(function (req, res) {

  var pathname = require('url').parse(req.url).pathname;
  var secret = pathname.split("/")[2];
  if (secret && secret.endsWith(".json")){
    secret = secret.substr(0, secret.length - 5);
    res.requestsJson = true;
  }        
  var filename = pathname.split("/")[3] || null
  var query = require('url').parse(req.url, true).query;    
  var device = query.device_id || guid();  
  
  console.log(req.method + ": " + util.inspect(secret) + " " + filename);

  if (watchers[secret] === undefined) watchers[secret] = [];
  if (waitingReceivers[secret] === undefined) waitingReceivers[secret] = [];
  if (messagecache[secret] === undefined) messagecache[secret] = [];

  if (req.method === 'GET' && pathname.indexOf('/api') == 0) {

    if (query.watch == 'listeners') {

      if (waitingReceivers[secret].length != query.count){
        res.writeHead(200, header);
        res.end(waitingReceivers[secret].length + '\n');
      } else{
        res.knownNumberOfListeners = query.count;
        watchers[secret].push(res);
      }
      track("watch-listeners");
      return;
    }
    
    if (filename === null){
    
      if (res.requestsJson){
        var messages = [];
        var since = 0;
        messagecache[secret].forEach(function(msg, i){
          if (query.since === msg.id)
            since += i+1;
          if (msg.sender !== device)
            messages.push(msg);
          else
            since--;
        });
        if (since > 0)
          messages = messages.splice(since);
        if (messages.length > 0){
          res.writeHead(200);
          res.end(JSON.stringify(messages));
          return;
        }
      }

      req.connection.on('close',function(){
         res.aborted = true;
         track("get-aborted");
        
         var livingwaitingReceivers = [];
         waitingReceivers[secret].forEach(function(response){
           if (!response.aborted) livingwaitingReceivers.push(response);
         });

         waitingReceivers[secret] = livingwaitingReceivers;        
         updateWatchers(secret);
      });
  
      res.device = device;
      
      // if not asking for a file we will wait for the shared data
      waitingReceivers[secret].push(res); 
      track("get-waiting");
      
      updateWatchers(secret);
      return;
    }

    if (filename === "recent-data.json"){
      res.writeHead(200);
      res.end(JSON.stringify(messagecache[secret]));
      return;

    } else if (filecache[pathname] != undefined){
      var file = growingfile.open(filecache[pathname].path);
      var header = { 
          'Content-Type': (filecache[pathname].mimetype || filecache[pathname].mime),
      } 
      if (filecache[pathname].contentLength) header['Content-Length'] = filecache[pathname].contentLength;
      res.writeHead(200, header);
      track("get-file-200");
      file.pipe(res);
    } else {
      res.writeHead(404);
      track("get-file-404");
      res.end();
    }
 
  } else if (req.method === 'PUT' && pathname.indexOf('/api') == 0) {
    //console.log("PUT waitingReceivers  " + waitingReceivers[secret].length);

    
    req.on('data', function(chunk) {

      var keepFor = (query.keep_for || 60);
      var msg = {data: chunk.toString(), id: guid(), sender: device};
      messagecache[secret].push(ce.clone(msg));
      setTimeout(function(){
       messagecache[secret].splice(messagecache[secret].indexOf(msg), 1);
      }, 1000 * keepFor );

      var receiverWhoSendsTheData;
      waitingReceivers[secret].forEach(function(response){
        if (response.device !== device || !device){
          response.writeHead(200, header);
          track("get-200");
          if (response.requestsJson)
            response.end(JSON.stringify([msg]));
          else
            response.end(chunk);
        } else
          receiverWhoSendsTheData = response;
      });

      track("put-" + waitingReceivers[secret].length);

      res.writeHead(200, header);
      
      msg.deliveries = (waitingReceivers[secret].length - (receiverWhoSendsTheData ? 1 : 0));
      if (res.requestsJson){
          msg.keep_for = keepFor; 
          res.end(JSON.stringify(msg));
      } else
          res.end( msg.deliveries + '\n');

      if (receiverWhoSendsTheData)
        waitingReceivers[secret] = [receiverWhoSendsTheData];
      else
        waitingReceivers[secret] = [];

      updateWatchers(secret);
   });

  } else if (req.method === 'POST' && pathname.indexOf('/api') == 0) {

    if (!filename) {
      track("post-403");
      res.writeHead(403);
      res.end();
      return;
    }
    
    var form = new formidable.IncomingForm();

      form.on('fileBegin', function(name, file){
        filecache[pathname] = file;
      });


      form.on('progress', function(received, expected){
        if (received > 10 && filecache[pathname] && !filecache[pathname].mimetype){
          mime.fileWrapper(filecache[pathname].path + ".pdf", function (err, type) {
            if (err)
                filecache[pathname].mimetype = require('mime').lookup(pathname);
            else
              filecache[pathname].mimetype = type;
          //filecache[pathname].contentLength = expected  - 300;
          });
        }
      });

      form.parse(req, function(err, fields, files) {
        if (err) {
          res.writeHead(500); res.end();
          track("post-500");
          return;
        }
        var file = files.file || files.data;
        if (!filecache[pathname]) {
          filecache[pathname] = file;
          mime.fileWrapper(filecache[pathname].path + ".pdf", function (err, type) {
            if (err)
                filecache[pathname].mimetype = require('mime').lookup(pathname);
            else
              filecache[pathname].mimetype = type;
          });
        }      
        res.writeHead(200, {'content-type': 'text/plain'});
        res.end('{"url": "'+ pathname + '"}');
        track("post-200");
        filecache[pathname].contentLength = file.length;
        setTimeout(function(){ 
          fs.unlink(file.path);
        }, 10 * 60 * 1000);
      });
      
  }

  if (pathname.indexOf('/api') == 0) return;

  var filePath = '.' + req.url;
  if (filePath == './')
    filePath = './index.html';
  filePath = 'web-client/' + filePath;    

    var extname = path.extname(filePath);
    var contentType = 'text/html';
    switch (extname) {
        case '.png':
            contentType = 'image/png';
            break;
        case '.ico':
            contentType = 'image/x-icon';
            break;
        case '.js':
            contentType = 'text/javascript';
            break;
        case '.css':
            contentType = 'text/css';
            break;
    }
     
    fs.exists(filePath, function(exists) {
     
        if (exists) {
            fs.readFile(filePath, function(error, content) {
                if (error) {
                    res.writeHead(500);
                    res.end();
                }
                else {
                    res.writeHead(200, { 'Content-Type': contentType });
                    res.end(content, 'utf-8');
                }
            });
        }
        else {
            res.writeHead(404);
            res.end();
        }
    });


}).listen(port);