1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-05 10:39:25 +02:00

Attempt to relaunch agent/service instead of dying instantly.

This commit is contained in:
Simo Kinnunen 2014-09-05 19:51:30 +09:00
parent 869f1ed7ac
commit 9dcd327420

View file

@ -69,7 +69,6 @@ module.exports = syrup.serial()
.timeout(10000) .timeout(10000)
}) })
.then(function(out) { .then(function(out) {
lifecycle.share('Agent shell', out)
streamutil.talk(log, 'Agent says: "%s"', out) streamutil.talk(log, 'Agent says: "%s"', out)
}) })
.then(function() { .then(function() {
@ -80,10 +79,33 @@ module.exports = syrup.serial()
agent.socket = conn agent.socket = conn
agent.writer = new ms.DelimitingStream() agent.writer = new ms.DelimitingStream()
agent.writer.pipe(conn) agent.writer.pipe(conn)
lifecycle.share('Agent connection', conn) return prepareForAgentDeath(conn)
}) })
} }
function prepareForAgentDeath(conn) {
function endListener() {
var startTime = Date.now()
log.important('Agent connection ended, attempting to relaunch')
openService()
.timeout(5000)
.then(function() {
log.important('Agent relaunched in %dms', Date.now() - startTime)
})
.catch(function(err) {
log.fatal('Agent connection could not be relaunched', err.stack)
lifecycle.fatal()
})
}
conn.once('end', endListener)
conn.on('error', function(err) {
log.fatal('Agent connection had an error', err.stack)
lifecycle.fatal()
})
}
function stopAgent() { function stopAgent() {
return devutil.killProcsByComm( return devutil.killProcsByComm(
adb adb
@ -162,10 +184,33 @@ module.exports = syrup.serial()
service.reader.on('data', handleEnvelope) service.reader.on('data', handleEnvelope)
service.writer = new ms.DelimitingStream() service.writer = new ms.DelimitingStream()
service.writer.pipe(conn) service.writer.pipe(conn)
lifecycle.share('Service connection', conn) return prepareForServiceDeath(conn)
}) })
} }
function prepareForServiceDeath(conn) {
function endListener() {
var startTime = Date.now()
log.important('Service connection ended, attempting to relaunch')
openService()
.timeout(5000)
.then(function() {
log.important('Service relaunched in %dms', Date.now() - startTime)
})
.catch(function(err) {
log.fatal('Service connection could not be relaunched', err.stack)
lifecycle.fatal()
})
}
conn.once('end', endListener)
conn.on('error', function(err) {
log.fatal('Service connection had an error', err.stack)
lifecycle.fatal()
})
}
function handleEnvelope(data) { function handleEnvelope(data) {
var envelope = apk.wire.Envelope.decode(data) var envelope = apk.wire.Envelope.decode(data)
, message , message