Add timeouts everywhere. Should help if the ADB socket gets stuck like it sometimes does.

This commit is contained in:
Simo Kinnunen
2014-04-02 11:58:53 +09:00
parent 64d4782436
commit 0ce65687c5
10 changed files with 51 additions and 5 deletions

View File

@@ -12,6 +12,7 @@ module.exports = syrup()
log.info('Fetching browser list')
return input.getBrowsers()
.timeout(15000)
.then(function(browsers) {
var icons = Object.create(null)

View File

@@ -27,12 +27,14 @@ module.exports = syrup.serial()
function openService() {
log.info('Launching HTTP API')
return devutil.ensureUnusedPort(adb, options.serial, service.port)
.timeout(10000)
.then(function() {
return adb.shell(options.serial, [
remote.bin
, '--lib', remote.lib
, '--listen-http', service.port
])
.timeout(10000)
.then(function(out) {
lifecycle.share('Remote shell', out)
streamutil.talk(log, 'Remote shell says: "%s"', out)
@@ -40,6 +42,7 @@ module.exports = syrup.serial()
.then(function() {
return devutil.waitForPort(adb, options.serial, service.port)
})
.timeout(20000)
.then(function(conn) {
var ours = options.ports.pop()
, everyones = options.ports.pop()
@@ -62,6 +65,7 @@ module.exports = syrup.serial()
, util.format('tcp:%d', ours)
, util.format('tcp:%d', service.port)
)
.timeout(10000)
.then(function() {
log.info(
'Opening HTTP API proxy on "http://%s:%s"'
@@ -113,6 +117,7 @@ module.exports = syrup.serial()
)
, json: true
})
.timeout(10000)
.then(function(args) {
var display = args[1]
assert.ok('id' in display, 'Invalid response from HTTP API')

View File

@@ -37,9 +37,11 @@ module.exports = syrup.serial()
function openAgent() {
log.info('Launching input agent')
return stopAgent()
.timeout(15000)
.then(function() {
return devutil.ensureUnusedPort(adb, options.serial, agent.port)
})
.timeout(10000)
.then(function() {
return adb.shell(options.serial, util.format(
"export CLASSPATH='%s'; exec app_process /system/bin '%s'"
@@ -47,6 +49,7 @@ module.exports = syrup.serial()
, apk.main
))
})
.timeout(10000)
.then(function(out) {
lifecycle.share('InputAgent shell', out)
streamutil.talk(log, 'InputAgent says: "%s"', out)
@@ -54,6 +57,7 @@ module.exports = syrup.serial()
.then(function() {
return devutil.waitForPort(adb, options.serial, agent.port)
})
.timeout(10000)
.then(function(conn) {
agent.socket = conn
agent.writer = new ms.DelimitingStream()
@@ -76,22 +80,26 @@ module.exports = syrup.serial()
'am startservice --user 0 %s'
, intent
))
.timeout(15000)
.then(function(out) {
return streamutil.findLine(out, /^Error/)
.finally(function() {
out.end()
})
.timeout(10000)
.then(function(line) {
if (line.indexOf('--user') !== -1) {
return adb.shell(options.serial, util.format(
'am startservice %s'
, intent
))
.timeout(15000)
.then(function() {
return streamutil.findLine(out, /^Error/)
.finally(function() {
out.end()
})
.timeout(10000)
.then(function(line) {
throw new Error(util.format(
'Service had an error: "%s"'
@@ -119,15 +127,18 @@ module.exports = syrup.serial()
function openService() {
log.info('Launching input service')
return stopService()
.timeout(15000)
.then(function() {
return devutil.waitForPortToFree(adb, options.serial, service.port)
})
.timeout(10000)
.then(function() {
return callService(util.format("-a '%s'", apk.startAction))
})
.then(function() {
return devutil.waitForPort(adb, options.serial, service.port)
})
.timeout(15000)
.then(function(conn) {
service.socket = conn
service.reader = conn.pipe(new ms.DelimitedStream())
@@ -159,6 +170,7 @@ module.exports = syrup.serial()
apk.serviceProto.RequestType.VERSION
, new apk.serviceProto.VersionRequest()
)
.timeout(10000)
.then(function(data) {
var response = apk.serviceProto.VersionResponse.decode(data)
if (response.success) {
@@ -173,6 +185,7 @@ module.exports = syrup.serial()
apk.serviceProto.RequestType.SET_KEYGUARD_STATE
, new apk.serviceProto.SetKeyguardStateRequest(false)
)
.timeout(10000)
.then(function(data) {
var response = apk.serviceProto.SetKeyguardStateResponse.decode(data)
if (!response.success) {
@@ -186,6 +199,7 @@ module.exports = syrup.serial()
apk.serviceProto.RequestType.SET_KEYGUARD_STATE
, new apk.serviceProto.SetKeyguardStateRequest(true)
)
.timeout(10000)
.then(function(data) {
var response = apk.serviceProto.SetKeyguardStateResponse.decode(data)
if (!response.success) {
@@ -199,6 +213,7 @@ module.exports = syrup.serial()
apk.serviceProto.RequestType.SET_WAKE_LOCK
, new apk.serviceProto.SetWakeLockRequest(true)
)
.timeout(10000)
.then(function(data) {
var response = apk.serviceProto.SetWakeLockResponse.decode(data)
if (!response.success) {
@@ -212,6 +227,7 @@ module.exports = syrup.serial()
apk.serviceProto.RequestType.SET_WAKE_LOCK
, new apk.serviceProto.SetWakeLockRequest(false)
)
.timeout(10000)
.then(function(data) {
var response = apk.serviceProto.SetWakeLockResponse.decode(data)
if (!response.success) {
@@ -225,6 +241,7 @@ module.exports = syrup.serial()
apk.serviceProto.RequestType.IDENTIFY
, new apk.serviceProto.IdentifyRequest(options.serial)
)
.timeout(10000)
.then(function(data) {
var response = apk.serviceProto.IdentifyResponse.decode(data)
if (!response.success) {
@@ -241,6 +258,7 @@ module.exports = syrup.serial()
, text
)
)
.timeout(10000)
.then(function(data) {
var response = apk.serviceProto.SetClipboardResponse.decode(data)
if (!response.success) {
@@ -256,6 +274,7 @@ module.exports = syrup.serial()
apk.serviceProto.ClipboardType.TEXT
)
)
.timeout(10000)
.then(function(data) {
var response = apk.serviceProto.GetClipboardResponse.decode(data)
if (response.success) {
@@ -273,6 +292,7 @@ module.exports = syrup.serial()
apk.serviceProto.RequestType.GET_BROWSERS
, new apk.serviceProto.GetBrowsersRequest()
)
.timeout(15000)
.then(function(data) {
var response = apk.serviceProto.GetBrowsersResponse.decode(data)
if (response.success) {

View File

@@ -49,6 +49,7 @@ module.exports = syrup.serial()
var target = '/data/local/tmp/_app.apk'
return adb.push(options.serial, source, target)
.timeout(10000)
.then(function(transfer) {
var resolver = Promise.defer()
@@ -93,6 +94,7 @@ module.exports = syrup.serial()
sendProgress('Installing app', 80)
return adb.installRemote(options.serial, apk)
})
.timeout(10000)
.then(function() {
if (message.launchActivity) {
log.info(
@@ -105,6 +107,7 @@ module.exports = syrup.serial()
return adb.startActivity(options.serial, message.launchActivity)
}
})
.timeout(15000)
.then(function() {
push.send([
channel

View File

@@ -16,6 +16,7 @@ module.exports = syrup.serial()
function openService() {
log.info('Launching logcat service')
return adb.openLogcat(options.serial)
.timeout(10000)
.then(function(logcat) {
return lifecycle.share('Logcat', logcat)
})

View File

@@ -19,6 +19,7 @@ module.exports = syrup.serial()
log.info('Running shell command "%s"', message.command)
adb.shell(options.serial, message.command)
.timeout(10000)
.then(function(stream) {
var resolver = Promise.defer()
, timer

View File

@@ -17,6 +17,7 @@ module.exports = syrup.serial()
function openService() {
return devutil.ensureUnusedPort(adb, options.serial, service.port)
.timeout(10000)
.then(function() {
return adb.shell(options.serial, [
remote.bin
@@ -28,9 +29,11 @@ module.exports = syrup.serial()
streamutil.talk(log, 'Stats shell says: "%s"', out)
})
})
.timeout(10000)
.then(function() {
return devutil.waitForPort(adb, options.serial, service.port)
})
.timeout(15000)
.then(function(conn) {
return lifecycle.share('Stats connection', conn)
})

View File

@@ -22,6 +22,7 @@ module.exports = syrup.serial()
function openService() {
log.info('Launching touch service')
return devutil.ensureUnusedPort(adb, options.serial, service.port)
.timeout(10000)
.then(function() {
return adb.shell(options.serial, [
remote.bin
@@ -29,6 +30,7 @@ module.exports = syrup.serial()
, '--listen-input', service.port
])
})
.timeout(10000)
.then(function(out) {
lifecycle.share('Touch shell', out)
streamutil.talk(log, 'Touch shell says: "%s"', out)
@@ -36,6 +38,7 @@ module.exports = syrup.serial()
.then(function() {
return devutil.waitForPort(adb, options.serial, service.port)
})
.timeout(15000)
.then(function(conn) {
return Promise.promisifyAll(monkey.connectStream(conn))
})

View File

@@ -36,6 +36,7 @@ module.exports = syrup.serial()
function removeResource(res) {
return adb.shell(options.serial, ['rm', res.dest])
.timeout(10000)
.then(function(out) {
return streamutil.readAll(out)
})
@@ -44,6 +45,7 @@ module.exports = syrup.serial()
function installResource(res) {
return adb.push(options.serial, res.src, res.dest, res.mode)
.timeout(10000)
.then(function(transfer) {
return new Promise(function(resolve, reject) {
transfer.on('error', reject)
@@ -55,9 +57,11 @@ module.exports = syrup.serial()
function ensureNotBusy(res) {
return adb.shell(options.serial, [res.dest, '--help'])
.timeout(10000)
.then(function(out) {
// Can be "Text is busy", "text busy"
return streamutil.findLine(out, (/busy/i))
.timeout(10000)
.then(function() {
log.info('Binary is busy, will retry')
return Promise.delay(1000)
@@ -80,11 +84,12 @@ module.exports = syrup.serial()
function stop() {
return devutil.killProcsByComm(
adb
, options.serial
, resources.bin.comm
, resources.bin.dest
)
adb
, options.serial
, resources.bin.comm
, resources.bin.dest
)
.timeout(15000)
}
return stop()

View File

@@ -30,8 +30,10 @@ module.exports = syrup.serial()
function getPath() {
return adb.shell(options.serial, ['pm', 'path', resource.pkg])
.timeout(10000)
.then(function(out) {
return streamutil.findLine(out, (/^package:/))
.timeout(15000)
.then(function(line) {
return line.substr(8)
})
@@ -49,6 +51,7 @@ module.exports = syrup.serial()
, installedPath
, resource.main
))
.timeout(10000)
.then(function(out) {
return streamutil.readAll(out)
.timeout(10000)
@@ -69,6 +72,7 @@ module.exports = syrup.serial()
.catch(function() {
log.info('Installing STFService')
return adb.install(options.serial, resource.apk)
.timeout(30000)
.then(function() {
return getPath()
})