Ejemplo n.º 1
0
 afterEach(function () {
   // Common assertions
   proc.fork.should.be.calledOnce;
   proc.fork.should.be.calledWith(sinon.match.string, sinon.match.array);
   // Restore fork functionality
   proc.fork.restore();
 });
Ejemplo n.º 2
0
 beforeEach(function () {
   sinon.stub(proc, 'fork');
   this.childOn = sinon.stub();
   proc.fork.returns({
     stdout: sinon.stub(through()),
     stderr: sinon.stub(through()),
     on: this.childOn
   });
 });
Ejemplo n.º 3
0
module.exports.fork = function(filename, args) {
  log.info('Forking "%s %s"', filename, args.join(' '))

  var resolver = Promise.defer()

  var proc = cp.fork.apply(cp, arguments)

  function sigintListener() {
    proc.kill('SIGINT')
  }

  function sigtermListener() {
    proc.kill('SIGTERM')
  }

  process.on('SIGINT', sigintListener)
  process.on('SIGTERM', sigtermListener)

  proc.on('error', function(err) {
    resolver.reject(err)
    proc.kill()
  })

  proc.on('exit', function(code, signal) {
    if (signal) {
      resolver.resolve(code)
    }
    else if (code > 0 && code !== 130 && code !== 143) {
      resolver.reject(new ExitError(code))
    }
    else {
      resolver.resolve(code)
    }
  })

  return resolver.promise.cancellable()
    .finally(function() {
      process.removeListener('SIGINT', sigintListener)
      process.removeListener('SIGTERM', sigtermListener)
    })
    .catch(Promise.CancellationError, function() {
      return new Promise(function(resolve) {
        proc.on('exit', function() {
          resolve()
        })
        proc.kill()
      })
    })
}
Ejemplo n.º 4
0
 it('creates a new scraper process', () => {
   ScraperRunner._runScraper(fakeScraperPath, [fakeJob.account], fakeJob);
   assert.ok(childProcess.fork.calledWith(fakeScraperPath, [fakeJob.account]));
 });