mirror of
https://github.com/openstf/stf
synced 2025-10-05 10:39:25 +02:00
Don't allow minicap to fail more than 3 times in 10s.
This commit is contained in:
parent
688ddda713
commit
2123a475e3
2 changed files with 54 additions and 0 deletions
|
@ -16,6 +16,7 @@ var FrameConfig = require('./util/frameconfig')
|
||||||
var BroadcastSet = require('./util/broadcastset')
|
var BroadcastSet = require('./util/broadcastset')
|
||||||
var StateQueue = require('./util/statequeue')
|
var StateQueue = require('./util/statequeue')
|
||||||
var RiskyStream = require('./util/riskystream')
|
var RiskyStream = require('./util/riskystream')
|
||||||
|
var FailCounter = require('./util/failcounter')
|
||||||
|
|
||||||
module.exports = syrup.serial()
|
module.exports = syrup.serial()
|
||||||
.dependency(require('../../support/adb'))
|
.dependency(require('../../support/adb'))
|
||||||
|
@ -38,6 +39,9 @@ module.exports = syrup.serial()
|
||||||
this.readable = false
|
this.readable = false
|
||||||
this.needsReadable = false
|
this.needsReadable = false
|
||||||
this.starter = Promise.resolve(true)
|
this.starter = Promise.resolve(true)
|
||||||
|
this.failCounter = new FailCounter(3, 10000)
|
||||||
|
this.failCounter.on('exceedLimit', this._failLimitExceeded.bind(this))
|
||||||
|
this.failed = false
|
||||||
}
|
}
|
||||||
|
|
||||||
util.inherits(FrameProducer, EventEmitter)
|
util.inherits(FrameProducer, EventEmitter)
|
||||||
|
@ -52,6 +56,11 @@ module.exports = syrup.serial()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.failed) {
|
||||||
|
log.warn('Will not apply desired state due to too many failures')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
switch (this.runningState) {
|
switch (this.runningState) {
|
||||||
case FrameProducer.STATE_STARTING:
|
case FrameProducer.STATE_STARTING:
|
||||||
case FrameProducer.STATE_STOPPING:
|
case FrameProducer.STATE_STOPPING:
|
||||||
|
@ -88,6 +97,7 @@ module.exports = syrup.serial()
|
||||||
})
|
})
|
||||||
.catch(function(err) {
|
.catch(function(err) {
|
||||||
return this._stop().finally(function() {
|
return this._stop().finally(function() {
|
||||||
|
this.failCounter.inc()
|
||||||
this.emit('error', err)
|
this.emit('error', err)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -191,14 +201,26 @@ module.exports = syrup.serial()
|
||||||
|
|
||||||
FrameProducer.prototype._socketEnded = function() {
|
FrameProducer.prototype._socketEnded = function() {
|
||||||
log.warn('Connection to minicap ended unexpectedly')
|
log.warn('Connection to minicap ended unexpectedly')
|
||||||
|
this.failCounter.inc()
|
||||||
this.restart()
|
this.restart()
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameProducer.prototype._outputEnded = function() {
|
FrameProducer.prototype._outputEnded = function() {
|
||||||
log.warn('Shell keeping minicap running ended unexpectedly')
|
log.warn('Shell keeping minicap running ended unexpectedly')
|
||||||
|
this.failCounter.inc()
|
||||||
this.restart()
|
this.restart()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FrameProducer.prototype._failLimitExceeded = function(limit, time) {
|
||||||
|
this._stop()
|
||||||
|
this.failed = true
|
||||||
|
this.emit('error', new Error(util.format(
|
||||||
|
'Failed more than %d times in %dms'
|
||||||
|
, limit
|
||||||
|
, time
|
||||||
|
)))
|
||||||
|
}
|
||||||
|
|
||||||
FrameProducer.prototype._startService = function() {
|
FrameProducer.prototype._startService = function() {
|
||||||
log.info('Launching screen service')
|
log.info('Launching screen service')
|
||||||
return minicap.run(util.format('-S -P %s', this.frameConfig.toString()))
|
return minicap.run(util.format('-S -P %s', this.frameConfig.toString()))
|
||||||
|
|
32
lib/units/device/plugins/screen/util/failcounter.js
Normal file
32
lib/units/device/plugins/screen/util/failcounter.js
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
var util = require('util')
|
||||||
|
|
||||||
|
var EventEmitter = require('eventemitter3').EventEmitter
|
||||||
|
|
||||||
|
function FailCounter(threshold, time) {
|
||||||
|
this.threshold = threshold
|
||||||
|
this.time = time
|
||||||
|
this.values = []
|
||||||
|
}
|
||||||
|
|
||||||
|
util.inherits(FailCounter, EventEmitter)
|
||||||
|
|
||||||
|
FailCounter.prototype.inc = function() {
|
||||||
|
var now = Date.now()
|
||||||
|
|
||||||
|
while (this.values.length) {
|
||||||
|
if (now - this.values[0] >= this.time) {
|
||||||
|
this.values.shift()
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.values.push(now)
|
||||||
|
|
||||||
|
if (this.values.length > this.threshold) {
|
||||||
|
this.emit('exceedLimit', this.threshold, this.time)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = FailCounter
|
Loading…
Add table
Add a link
Reference in a new issue