mirror of
https://github.com/openstf/stf
synced 2025-10-05 10:39:25 +02:00
Move some screen utilities to the global util directory so that they can be used for other things too.
This commit is contained in:
parent
ae9f2b5ab0
commit
5bb05f52f6
4 changed files with 3 additions and 3 deletions
|
@ -14,9 +14,9 @@ var bannerutil = require('./util/banner')
|
|||
var FrameParser = require('./util/frameparser')
|
||||
var FrameConfig = require('./util/frameconfig')
|
||||
var BroadcastSet = require('./util/broadcastset')
|
||||
var StateQueue = require('./util/statequeue')
|
||||
var RiskyStream = require('./util/riskystream')
|
||||
var FailCounter = require('./util/failcounter')
|
||||
var StateQueue = require('../../../../util/statequeue')
|
||||
var RiskyStream = require('../../../../util/riskystream')
|
||||
var FailCounter = require('../../../../util/failcounter')
|
||||
|
||||
module.exports = syrup.serial()
|
||||
.dependency(require('../../support/adb'))
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
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
|
|
@ -1,35 +0,0 @@
|
|||
var util = require('util')
|
||||
|
||||
var EventEmitter = require('eventemitter3').EventEmitter
|
||||
|
||||
function RiskyStream(stream) {
|
||||
this.endListener = function() {
|
||||
this.ended = true
|
||||
this.stream.removeListener('end', this.endListener)
|
||||
|
||||
if (!this.expectingEnd) {
|
||||
this.emit('unexpectedEnd')
|
||||
}
|
||||
|
||||
this.emit('end')
|
||||
}.bind(this)
|
||||
|
||||
this.stream = stream
|
||||
.on('end', this.endListener)
|
||||
this.expectingEnd = false
|
||||
this.ended = false
|
||||
}
|
||||
|
||||
util.inherits(RiskyStream, EventEmitter)
|
||||
|
||||
RiskyStream.prototype.end = function() {
|
||||
this.expectEnd()
|
||||
return this.stream.end()
|
||||
}
|
||||
|
||||
RiskyStream.prototype.expectEnd = function() {
|
||||
this.expectingEnd = true
|
||||
return this
|
||||
}
|
||||
|
||||
module.exports = RiskyStream
|
|
@ -1,30 +0,0 @@
|
|||
function StateQueue() {
|
||||
this.queue = []
|
||||
}
|
||||
|
||||
StateQueue.prototype.next = function() {
|
||||
return this.queue.shift()
|
||||
}
|
||||
|
||||
StateQueue.prototype.empty = function() {
|
||||
return this.queue.length === 0
|
||||
}
|
||||
|
||||
StateQueue.prototype.push = function(state) {
|
||||
var found = false
|
||||
|
||||
// Not super efficient, but this shouldn't be running all the time anyway.
|
||||
for (var i = 0, l = this.queue.length; i < l; ++i) {
|
||||
if (this.queue[i] === state) {
|
||||
this.queue.splice(i + 1)
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
this.queue.push(state)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = StateQueue
|
Loading…
Add table
Add a link
Reference in a new issue