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

Make absolutely sure that we kill old procs.

This commit is contained in:
Simo Kinnunen 2014-01-29 17:00:45 +09:00
parent a8914297ad
commit 315418d790

View file

@ -57,12 +57,12 @@ devutil.waitForPort = function(adb, serial, port) {
}) })
} }
devutil.killProcsByComm = function(adb, serial, comm, bin) { devutil.listPidsByComm = function(adb, serial, comm, bin) {
return adb.shellAsync(serial, ['ps', comm]) return adb.shellAsync(serial, ['ps', comm])
.then(function(out) { .then(function(out) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
var header = false var header = false
, killables = [] , pids = []
out.pipe(split()) out.pipe(split())
.on('data', function(chunk) { .on('data', function(chunk) {
if (header) { if (header) {
@ -71,27 +71,48 @@ devutil.killProcsByComm = function(adb, serial, comm, bin) {
else { else {
var cols = chunk.toString().split(/\s+/) var cols = chunk.toString().split(/\s+/)
if (cols.pop() === bin) { if (cols.pop() === bin) {
killables.push(cols[1]) pids.push(+cols[1])
} }
} }
}) })
.on('end', function() { .on('end', function() {
resolve(killables) resolve(pids)
}) })
}) })
}) })
.then(function(killables) { }
if (killables.length) {
return adb.shellAsync(serial, ['kill'].concat(killables)) devutil.waitForProcsToDie = function(adb, serial, comm, bin) {
.then(function(out) { return devutil.listPidsByComm(adb, serial, comm, bin)
return new Promise(function(resolve, reject) { .then(function(pids) {
out.on('end', resolve) if (pids.length) {
}) return devutil.waitForProcsToDie(adb, serial, comm, bin)
})
} }
}) })
} }
devutil.killProcsByComm = function(adb, serial, comm, bin, mode) {
return devutil.listPidsByComm(adb, serial, comm, bin, mode)
.then(function(pids) {
if (!pids.length) {
return Promise.resolve()
}
return adb.shellAsync(serial, ['kill', mode || -15].concat(pids))
.then(function(out) {
return new Promise(function(resolve, reject) {
out.on('end', resolve)
})
})
.then(function() {
return devutil.waitForProcsToDie(adb, serial, comm, bin)
})
.timeout(1000)
.then(function() {
return devutil.killProcsByComm(adb, serial, comm, bin, -9)
})
})
}
devutil.startProp = function(adb, serial, cmd) { devutil.startProp = function(adb, serial, cmd) {
return adb.openTcpAsync(options.serial, port) return adb.openTcpAsync(options.serial, port)
.then(function(conn) { .then(function(conn) {