aboutsummaryrefslogtreecommitdiffstats
path: root/vnfmarket/src/main/webapp/vnfmarket/node_modules/karma/lib/launchers/capture_timeout.js
blob: fe0e166db0c2f96b1cf58c14246847ea74977930 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
var log = require('../logger').create('launcher')

/**
 * Kill browser if it does not capture in given `captureTimeout`.
 */
var CaptureTimeoutLauncher = function (timer, captureTimeout) {
  if (!captureTimeout) {
    return
  }

  var self = this
  var pendingTimeoutId = null

  this.on('start', function () {
    pendingTimeoutId = timer.setTimeout(function () {
      pendingTimeoutId = null
      if (self.state !== self.STATE_BEING_CAPTURED) {
        return
      }

      log.warn('%s have not captured in %d ms, killing.', self.name, captureTimeout)
      self.error = 'timeout'
      self.kill()
    }, captureTimeout)
  })

  this.on('done', function () {
    if (pendingTimeoutId) {
      timer.clearTimeout(pendingTimeoutId)
      pendingTimeoutId = null
    }
  })
}

CaptureTimeoutLauncher.decoratorFactory = function (timer,
  /* config.captureTimeout */ captureTimeout) {
  return function (launcher) {
    CaptureTimeoutLauncher.call(launcher, timer, captureTimeout)
  }
}

CaptureTimeoutLauncher.decoratorFactory.$inject = ['timer', 'config.captureTimeout']

module.exports = CaptureTimeoutLauncher