1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 18:29:17 +02:00

Move more work to devutil.

This commit is contained in:
Simo Kinnunen 2014-01-29 14:13:52 +09:00
parent 3c55f91ee9
commit 6c350d0068
2 changed files with 31 additions and 27 deletions

View file

@ -90,33 +90,23 @@ module.exports = function(options) {
]) ])
}) })
.then(function() { .then(function() {
var port = 2870 return devutil.ensureUnusedPort(adb, options.serial, 2870)
return adb.openTcpAsync(options.serial, port) .then(function(port) {
.then(function(conn) { return adb.shellAsync(options.serial, [
conn.end() vendor.bin.dest
throw new Error(util.format('Old connection still lives on port %d', port)) , '--lib', vendor.lib.dest
}) , '--listen-http', port
.catch(function(err) { ])
if (err.message === 'closed') { .then(function(out) {
return adb.shellAsync(options.serial, [ out.pipe(require('split')())
vendor.bin.dest .on('data', function(chunk) {
, '--lib', vendor.lib.dest log.info('remote: "%s"', chunk)
, '--listen-http', port })
]) .on('end', function() {
.then(function(out) { log.fatal('remote: Connection closed')
out.pipe(require('split')()) selfDestruct()
.on('data', function(chunk) { })
log.info('remote: "%s"', chunk) })
})
.on('end', function() {
log.fatal('remote: Connection closed')
selfDestruct()
})
})
}
else {
throw err
}
}) })
}) })
.done(function() { .done(function() {

View file

@ -26,6 +26,20 @@ devutil.vendorFiles = function(identity) {
} }
} }
devutil.ensureUnusedPort = function(adb, serial, port) {
function closedError(err) {
return err.message === 'closed'
}
return adb.openTcpAsync(serial, port)
.then(function(conn) {
conn.end()
throw new Error(util.format('Port "%d" should be unused', port))
})
.catch(closedError, function(err) {
return Promise.resolve(port)
})
}
devutil.killProcsByComm = function(adb, serial, comm, bin) { devutil.killProcsByComm = function(adb, serial, comm, bin) {
return adb.shellAsync(serial, ['ps', comm]) return adb.shellAsync(serial, ['ps', comm])
.then(function(out) { .then(function(out) {