Skip to content

Commit

Permalink
Recover from unresponsive instruments process
Browse files Browse the repository at this point in the history
Register for kCGSNotificationAppUnresponsive and if the process is Instruments then terminate it.
This enables Appium to continue even when instruments is unresponsive. The current behavior is to wait forever.

To test this feature works properly, run ./instruments.sh from https://github.com/appium/ForceQuitUnresponsiveApps

instruments.sh will launch a process that's unresponsive and appium will force quit the process. The unresponsive process can be visually confirmed by using OS X Activity Monitor.
  • Loading branch information
bootstraponline committed Dec 3, 2013
1 parent e07651d commit eaa6cb3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@
[submodule "submodules/libimobiledevice-macosx"]
path = submodules/libimobiledevice-macosx
url = https://github.com/benvium/libimobiledevice-macosx.git
[submodule "submodules/ForceQuitUnresponsiveApps"]
path = submodules/ForceQuitUnresponsiveApps
url = https://github.com/appium/ForceQuitUnresponsiveApps.git
27 changes: 25 additions & 2 deletions lib/server/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,29 @@ var http = require('http')
, _ = require("underscore")
, io = require('socket.io')
, gridRegister = require('./grid-register.js')
, bytes = require('bytes');
, bytes = require('bytes')
, isWindows = require('../helpers.js').isWindows()
, exec = require('child_process').exec
, spawn = require('child_process').spawn
, endInstrumentsPath = path.resolve(__dirname, '../../build/force_quit/ForceQuitUnresponsiveApps.app/Contents/MacOS/ForceQuitUnresponsiveApps');

var watchForUnresponsiveInstruments = function(cb) {
if (isWindows) return;

var endOldProcess = function(cb) {
exec("killall -9 ForceQuitUnresponsiveApps", { maxBuffer: 524288 }, function(err) { cb(); });
};

var startNewprocess = function(cb) {
spawn(endInstrumentsPath);
cb();
};

async.series([
endOldProcess,
startNewprocess
], cb);
};

var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
Expand All @@ -33,7 +55,7 @@ var allowCrossDomain = function(req, res, next) {

// need to respond 200 to OPTIONS

if ('OPTIONS' == req.method) {
if ('OPTIONS' === req.method) {
res.send(200);
} else {
next();
Expand Down Expand Up @@ -201,6 +223,7 @@ var main = function(args, readyCb, doneCb) {
var startListening = function(cb) {
var alreadyReturned = false;
server.listen(args.port, args.address, function() {
watchForUnresponsiveInstruments(function(){});
var welcome = "Welcome to Appium v" + appiumVer;
if (appiumRev) {
welcome += " (REV " + appiumRev + ")";
Expand Down
10 changes: 10 additions & 0 deletions reset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ reset_general() {

reset_ios() {
echo "RESETTING IOS"
echo "* Cloning/updating ForceQuitUnresponsiveApps"
run_cmd git submodule update --init submodules/ForceQuitUnresponsiveApps
echo "* Building ForceQuitUnresponsiveApps"
run_cmd pushd submodules/ForceQuitUnresponsiveApps
run_cmd ./build_force_quit.sh
run_cmd popd
echo "* Moving ForceQuitUnresponsiveApps into build/force_quit"
run_cmd rm -rf build/force_quit
run_cmd mkdir build/force_quit
run_cmd cp -R submodules/ForceQuitUnresponsiveApps/bin/* build/force_quit
echo "* Cloning/updating instruments-without-delay"
run_cmd git submodule update --init submodules/instruments-without-delay
echo "* Building instruments-without-delay"
Expand Down
1 change: 1 addition & 0 deletions submodules/ForceQuitUnresponsiveApps

0 comments on commit eaa6cb3

Please sign in to comment.