Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appium should detect when Instruments is not responding #1306

Closed
bootstraponline opened this issue Oct 11, 2013 · 29 comments · Fixed by #1565
Closed

Appium should detect when Instruments is not responding #1306

bootstraponline opened this issue Oct 11, 2013 · 29 comments · Fixed by #1565
Labels
Enhancement feature iOS related to iOS native driver(s)

Comments

@bootstraponline
Copy link
Member

The instruments process is consuming 300%+ CPU and appium hangs forever. What's going on? I suspect this is yet another gift from Apple.

@bootstraponline
Copy link
Member Author

Instruments often gets stuck at 100% CPU and appium hangs forever. Ending the process after each test helps, however it doesn't fix the issue. Appium should detect that Instruments isn't responding and end the session.

@bootstraponline
Copy link
Member Author

This still happens on OS X 10.9 + newest Appium on iOS 7.0.3 with Xcode 5.0.2.

Any thoughts on a work around?

@penguinho
Copy link
Member

There are private APIs to do this in OS X, you could write an app to poll it every 2 seconds or so and then terminate when the app is unresponsive

+ (bool) isProcessHanging:(int)pid
{
    pid_t p = (pid_t)pid;
    ProcessSerialNumber psn;
    OSStatus success = GetProcessForPID(p, &psn);
    if (success != 0)
        return false;
    CGSConnectionID myCid = _CGSDefaultConnection();
    return CGSEventIsAppUnresponsive(myCid, &psn);
}

@bootstraponline
Copy link
Member Author

Is there anything on Google about that API? I'm not seeing results.

@penguinho
Copy link
Member

there probably is. I think that's where I found it when I first used it; though it is a private API after all

@penguinho
Copy link
Member

@bootstraponline
Copy link
Member Author

It looks like I was using the wrong term. CGSEventIsAppUnresponsive finds a bunch of hits.

@penguinho
Copy link
Member

I believe there's also a way to register for a notification if you want to do it that way

@bootstraponline
Copy link
Member Author

That'd be better than polling.

@bootstraponline
Copy link
Member Author

This seems to do what I want.

@bootstraponline
Copy link
Member Author

@jlipps What do you think about integrating this into Appium so Instruments is ended when it hangs? The code will have to be modified so only Instruments is force quit.

@penguinho
Copy link
Member

I like that version better because it's not polling

@bootstraponline
Copy link
Member Author

I forked it. It looks like the only required change is filtering out non-Instruments processes.

  • I don't think checking localizedName would be reliable.
  • executableURL seems like a better way to identify the Instruments process.

@penguinho
Copy link
Member

though honestly one CGS call every 2 mins is not a huge polling hit on the system, and it lets you identify the process by pid

@bootstraponline
Copy link
Member Author

I think either approach is better than the current situation of hanging forever.

@bootstraponline
Copy link
Member Author

I think the notification way still lets us extract a pid.

@jlipps
Copy link
Member

jlipps commented Nov 11, 2013

The current situation is something hangs forever? I thought that's why we have a launchTimeout now.

@bootstraponline
Copy link
Member Author

Launch timeout only handles the launch case. If we're in the middle of the test and instruments flakes out, appium will not recover.

@jlipps
Copy link
Member

jlipps commented Nov 11, 2013

Ah didn't realized that happens. OK.

On Nov 11, 2013, at 2:00 PM, bootstraponline notifications@github.com wrote:

Launch timeout only handles the launch case. If we're in the middle of the test and instruments flakes out, appium will not recover.


Reply to this email directly or view it on GitHub.

@bootstraponline
Copy link
Member Author

It happens frequently when running multiple tests. :(

@bootstraponline
Copy link
Member Author

I have 47 moderately complex iOS tests and I can't make it through a complete run without triggering this issue.

@jlipps
Copy link
Member

jlipps commented Nov 13, 2013

I can run all the appium tests just fine without this happening; only instruments does hang on startup 1-2 times per test suite run

@bootstraponline
Copy link
Member Author

Happens all the time running the Woven tests. I'm happy to send those to you if you want to try.

@malafeev01
Copy link

I have this scenario:

  1. Launch test (any logic, for example: getting page_source in cycle).
  2. Close manually iPad Simulator (right click on simulator icon -> Quit).
�[90mdebug�[39m: Appium request initiated at /wd/hub/session/483a8d5b-c102-4f84-8ccb-a322d85365e7/source
�[90mdebug�[39m: Request received with params: {}
�[36minfo�[39m: Pushing command to appium work queue: "wd_frame.getPageSource()"
�[90mdebug�[39m: Sending command to instruments: wd_frame.getPageSource()
�[36minfo�[39m: �[90m[INSTSERVER] Sending command to instruments: wd_frame.getPageSource()�[39m
�[36minfo�[39m: �[32m[INST] 2013-11-22 08:04:03 +0000 Default: Got new command 43 from instruments: wd_frame.getPageSource()�[39m
�[36minfo�[39m: �[32m[INST] 2013-11-22 08:04:04 +0000 Fail: The target application appears to have died
        2013-11-22 08:04:04 +0000 Default: Result is not protocol compliant, wrapping�[39m
�[36minfo�[39m: �[90m[INSTSERVER] Socket data received (8192 bytes)�[39m
�[31merror�[39m: Couldn't parse JSON data from socket, maybe buffer issue?
�[31merror�[39m: {"event":"cmd","result":{"status":0,"value":"{\"name\":\"Supervisor\",\"type\":\"UIAApplication\",\"label\":\"Supervisor\",\"value\":null,\"rect\":{\"origin\":{\"x\":0,\"y\":20},\"size\":{\"width\":768,\"height\":1004}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[{\"name\":null,\"type\":\"UIAWindow\",\"label\":null,\"value\":null,\"rect\":{\"origin\":{\"x\":0,\"y\":0},\"size\":{\"width\":768,\"height\":1024}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[{\"name\":\"Agent Grid\",\"type\":\"UIANavigationBar\",\"label\":null,\"value\":null,\"rect\":{\"origin\":{\"x\":0,\"y\":20},\"size\":{\"width\":768,\"height\":44}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[{\"name\":null,\"type\":\"UIAImage\",\"label\":null,\"value\":null,\"rect\":{\"origin\":{\"x\":0,\"y\":0},\"size\":{\"width\":768,\"height\":64}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":false,\"children\":[{\"name\":null,\"type\":\"UIAImage\",\"label\":null,\"value\":null,\"rect\":{\"origin\":{\"x\":0,\"y\":64},\"size\":{\"width\":768,\"height\":1}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":false,\"children\":[]}]},{\"name\":\"UINavigationBarBackIndicatorDefault.png\",\"type\":\"UIAButton\",\"label\":\"Back\",\"value\":null,\"rect\":{\"origin\":{\"x\":8,\"y\":32},\"size\":{\"width\":13,\"height\":21}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":false,\"children\":[]},{\"name\":\"TinyIcon\",\"type\":\"UIAImage\",\"label\":null,\"value\":null,\"rect\":{\"origin\":{\"x\":16,\"y\":24},\"size\":{\"width\":60,\"height\":36}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":false,\"children\":[]},{\"name\":\"Agent Grid\",\"type\":\"UIAStaticText\",\"label\":\"Agent Grid\",\"value\":\"Agent Grid\",\"rect\":{\"origin\":{\"x\":341,\"y\":28},\"size\":{\"width\":86,\"height\":27}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[]},{\"name\":\"All\",\"type\":\"UIAButton\",\"label\":\"All\",\"value\":null,\"rect\":{\"origin\":{\"x\":604,\"y\":28},\"size\":{\"width\":19,\"height\":30}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[]},{\"name\":\"|\",\"type\":\"UIAButton\",\"label\":\"|\",\"value\":null,\"rect\":{\"origin\":{\"x\":631,\"y\":28},\"size\":{\"width\":12,\"height\":30}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[]},{\"name\":\"Fields\",\"type\":\"UIAButton\",\"label\":\"Fields\",\"value\":null,\"rect\":{\"origin\":{\"x\":651,\"y\":28},\"size\":{\"width\":46,\"height\":30}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[]},{\"name\":\"Tools\",\"type\":\"UIAButton\",\"label\":\"Tools\",\"value\":null,\"rect\":{\"origin\":{\"x\":705,\"y\":25},\"size\":{\"width\":54,\"height\":32}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[]}]},{\"name\":\"Agent Grid\",\"type\":\"UIACollectionView\",\"label\":\"Agent Grid\",\"value\":\"page 1 of 2\",\"rect\":{\"origin\":{\"x\":0,\"y\":64},\"size\":{\"width\":768,\"height\":960}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[{\"name\":\"Row 1: -Username: tsc\",\"type\":\"UIACollectionCell\",\"label\":\"Row 1: -Username: tsc\",\"value\":0,\"rect\":{\"origin\":{\"x\":0,\"y\":0},\"size\":{\"width\":200,\"height\":50}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":false,\"children\":[]},{\"name\":\"Row 1: -Customer: \",\"type\":\"UIACollectionCell\",\"label\":\"Row 1: -Customer: \",\"value\":0,\"rect\":{\"origin\":{\"x\":-168,\"y\":114},\"size\":{\"width\":200,\"height\":50}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":false,\"children\":[]},{\"name\":\"Row 1: -State: Logged Out\",\"type\":\"UIACollectionCell\",\"label\":\"Row 1: -State: Logged Out\",\"value\":0,\"rect\":{\"origin\":{\"x\":32,\"y\":114},\"size\":{\"width\":200,\"height\":50}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[]},{\"name\":\"Row 1: -State Since: Today @ 4:10 PM\",\"type\":\"UIACollectionCell\",\"label\":\"Row 1: -State Since: Today @ 4:10 PM\",\"value\":0,\"rect\":{\"origin\":{\"x\":232,\"y\":114},\"size\":{\"width\":200,\"height\":50}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[]},{\"name\":\"Row 1: -State Duration: 7h 53m 35s\",\"type\":\"UIACollectionCell\",\"label\":\"Row 1: -State Duration: 7h 53m 35s\",\"value\":0,\"rect\":{\"origin\":{\"x\":432,\"y\":114},\"size\":{\"width\":200,\"height\":50}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[]},{\"name\":\"Row 1: -On Call State Since: \",\"type\":\"UIACollectionCell\",\"label\":\"Row 1: -On Call State Since: \",\"value\":0,\"rect\":{\"origin\":{\"x\":632,\"y\":114},\"size\":{\"width\":200,\"height\":50}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[]},{\"name\":\"Row 1: -Call Type: \",\"type\":\"UIACollectionCell\",\"label\":\"Row 1: -Call Type: \",\"value\":0,\"rect\":{\"origin\":{\"x\":0,\"y\":0},\"size\":{\"width\":200,\"height\":50}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":false,\"children\":[]},{\"name\":\"Row 1: -Media Availability: N/A\",\"type\":\"UIACollectionCell\",\"label\":\"Row 1: -Media Availability: N/A\",\"value\":0,\"rect\":{\"origin\":{\"x\":0,\"y\":0},\"size\":{\"width\":200,\"height\":50}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":false,\"children\":[]},{\"name\":\"Row 1: -Campaign Name: \",\"type\":\"UIACollectionCell\",\"label\":\"Row 1: -Campaign Name: \",\"value\":0,\"rect\":{\"origin\":{\"x\":0,\"y\":0},\"size\":{\"width\":200,\"height\":50}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":false,\"children\":[]},{\"name\":\"Row 1: -After Call Work State Since: \",\"type\":\"UIACollectionCell\",\"label\":\"Row 1: -After Call Work State Since: \",\"value\":0,\"rect\":{\"origin\":{\"x\":0,\"y\":0},\"size\":{\"width\":200,\"height\":50}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":false,\"children\":[]},{\"name\":\"Row 1: -On Hold Duration: 0\",\"type\":\"UIACollectionCell\",\"label\":\"Row 1: -On Hold Duration: 0\",\"value\":0,\"rect\":{\"origin\":{\"x\":0,\"y\":0},\"size\":{\"width\":200,\"height\":50}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":false,\"children\":[]},{\"name\":\"Row 2: -Username: tsc_user_0011\",\"type\":\"UIACollectionCell\",\"label\":\"Row 2: -Username: tsc_user_0011\",\"value\":0,\"rect\":{\"origin\":{\"x\":0,\"y\":0},\"size\":{\"width\":200,\"height\":50}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":false,\"children\":[]},{\"name\":\"Row 2: -Customer: \",\"type\":\"UIACollectionCell\",\"label\":\"Row 2: -Customer: \",\"value\":0,\"rect\":{\"origin\":{\"x\":-168,\"y\":164},\"size\":{\"width\":200,\"height\":50}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":false,\"children\":[]},{\"name\":\"Row 2: -State: Logged Out\",\"type\":\"UIACollectionCell\",\"label\":\"Row 2: -State: Logged Out\",\"value\":0,\"rect\":{\"origin\":{\"x\":32,\"y\":164},\"size\":{\"width\":200,\"height\":50}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[]},{\"name\":\"Row 2: -State Since: Today @ 4:10 PM\",\"type\":\"UIACollectionCell\",\"label\":\"Row 2: -State Since: Today @ 4:10 PM\",\"value\":0,\"rect\":{\"origin\":{\"x\":232,\"y\":164},\"size\":{\"width\":200,\"height\":50}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[]},{\"name\":\"Row 2: -State Duration: 7h 53m 35s\",\"type\":\"UIACollectionCell\",\"label\":\"Row 2: -State Duration: 7h 53m 35s\",\"value\":0,\"rect\":{\"origin\":{\"x\":432,\"y\":164},\"size\":{\"width\":200,\"height\":50}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[]},{\"name\":\"Row 2: -On Call State Since: \",\"type\":\"UIACollectionCell\",\"label\":\"Row 2: -On Call State Since: \",\"value\":0,\"rect\":{\"origin\":{\"x\":632,\"y\":164},\"size\":{\"width\":200,\"height\":50}},\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"children\":[]},{\"name\":\"Row 2: -Call Type: \",\"type\":\"UIACollectionCell\",\"label\":\"Row 2
�[36minfo�[39m: �[90m[INSTSERVER] Socket data being routed for 'cmd' event�[39m
�[36minfo�[39m: �[90m[INSTSERVER] Got result from instruments: {"status":{"code":13,"summary":"An unknown server-side error occurred while processing the command."},"value":"Error parsing socket data from instruments"}�[39m
�[36minfo�[39m: �[32m[INST] Instruments Trace Complete (Duration : 33.199738s; Output : /Users/XXXX/instrumentscli0.trace)
�[36minfo�[39m: �[90m[INSTSERVER] Instruments exited with code 0�[39m
�[36minfo�[39m: Stopping iOS log capture
�[36minfo�[39m: Cleaning up appium session
�[36minfo�[39m: �[90m[INSTSERVER] Socket closed forcibly due to exit�[39m
�[36minfo�[39m: �[90m[INSTSERVER] Instruments socket server closed�[39m
�[36minfo�[39m: Deleted tracedir we heard about from instruments (/Users/XXXX/instrumentscli0.trace)

According to log - "Instruments exited with code 0", but the test from step 1 nothing to knows about this and continues sending command requests.

Should Appium detect that intruments exited and pass this error to the test?

@bootstraponline
Copy link
Member Author

I updated the logic so only Instruments is ended. All the code is in this repository.

When running the binary I have to use this path /ForceQuitUnresponsiveApps.app/Contents/MacOS/ForceQuitUnresponsiveApps because it's built as a .app. I wonder if there's a command line build option that would make this work instead ForceQuitUnresponsiveApps

@jlipps Is this fine to integrate into appium?

Edit: From my testing it seems Cocoa is required which needs Info.plist meaning it can't be a command line app.

@jlipps
Copy link
Member

jlipps commented Dec 2, 2013

Yeah go ahead. How are you planning on integrating it?

@bootstraponline
Copy link
Member Author

How are you planning on integrating it?

  • On server start, end any existing ForceQuitUnresponsiveApps processes, and start the ForceQuitUnresponsiveApps process
  • If there are any problems, log a warning and continue

@jlipps
Copy link
Member

jlipps commented Dec 2, 2013

👍

@lock
Copy link

lock bot commented May 4, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators May 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Enhancement feature iOS related to iOS native driver(s)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants