Processes not ending - memory leak?

Mobile Testing, Android App Testing.
Otter_T
Posts: 18
Joined: Mon Aug 31, 2015 5:33 pm

Processes not ending - memory leak?

Post by Otter_T » Mon Nov 09, 2015 8:22 pm

Running Ranorex 5.4.3 on Win 7 64-bit.

Any time a test suite or standalone recording is run on an iOS device, Ranorex creates three new instances of the “iproxy.exe *32” process. These instances remain running after the test/recording finishes, so they pile up after multiple test runs. After roughly three dozen of these processes have piled up, Ranorex Studio stops communicating with the iOS device.

This occurs regardless of whether the “Close Application” action is used or not. If "Close Application" is used, it makes no difference if it's used with the “KillProcess” or “CloseWindow” option.

Not only do these “iproxy.exe *32” processes remain after the test finishes, they also remain even after Ranorex Studio is closed altogether. The processes can only be stopped manually (either one at a time in Windows Task Manager, or all at once with a command-line taskkill) or by rebooting the PC.

Is this a known issue? Is there a setting I need to change, either within Ranorex Studio or my PC?

Thank you.
You do not have the required permissions to view the files attached to this post.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Processes not ending - memory leak?

Post by Support Team » Tue Nov 10, 2015 1:58 pm

Hello Otter_T,

This issue is caused by the third-party tool, which is used to establish the USB connection to the device.
Unfortunately, we are not able to fix this bug, but we work on updating the iOS USB tools in the future.
I'm afraid I can't give you an exact time frame when this new version will be available.

As a workaround I would suggest connecting the iOS device via WiFi.

Thank you for your understanding.

Regards,
Johannes

Otter_T
Posts: 18
Joined: Mon Aug 31, 2015 5:33 pm

Re: Processes not ending - memory leak?

Post by Otter_T » Wed Dec 02, 2015 10:08 pm

Johannes, thanks for your reply. I created a simple vb script to terminate all instances of "iproxy.exe", which eliminates the need to open a command line and type it out, and I'd like to be able to turn this into a teardown action within a test suite so that it takes place automatically at the end of a test run. Can you offer any suggestions or refer me to any blog posts or documentation that would help me accomplish this?

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Processes not ending - memory leak?

Post by Support Team » Thu Dec 03, 2015 3:26 pm

Hi Otter_T,

Please follow the steps below to add a teardown region to your test suite:

1) First, choose the function Add Setup/Teardown from the context menu
add_setup_teardown.png
2) Add any Recording or Code Module to the teardown region
teardown_region.png
The teardown region will be executed when the execution of the test case has been finished, which means after all modules have been executed, or an error has aborted the test case. The teardown region should hold any modules needed to clean up the system under test and bring it to the original state.

More information about teardown and setup regions can be found in the user guide.

Regards,
Johannes
You do not have the required permissions to view the files attached to this post.

Otter_T
Posts: 18
Joined: Mon Aug 31, 2015 5:33 pm

Re: Processes not ending - memory leak?

Post by Otter_T » Mon Dec 21, 2015 6:48 pm

I cobbled together a procedure to terminate excess “iproxy.exe” instances, and thought I’d share it in case anyone else is looking for a workaround to this issue. The process consists of three steps: 1) creating a VB script to terminate all instances of “iproxy.exe” if there are more than five instances running, 2) creating a .bat file to call the VB script, and 3) placing a reference to the .bat file in a Ranorex recording.

1. Creating the .vbs file

Using a text editor (i.e. Notepad++), open a new document and paste in the following text:

Set objArgs = WScript.Arguments
strProcess = "iproxy.exe"
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("Select * from Win32_Process Where Name ='iproxy.exe'")

If colProcesses.Count > 5 Then
For Each objProcess in colProcesses
objProcess.Terminate(6)
Next
Else
End If


Save this file with the name “terminate_iproxy.vbs”. I saved mine in C:\Program Files (x86)\Ranorex 5.4, but you can save it wherever you’d like; just make sure you know the file path, because you’ll need it for the .bat file you’ll be creating next.

2. Creating the .bat file

Also using a text editor, open another new document and paste in the following:

start "" "C:\location of .vbs file\terminate_iproxy.vbs"

(So, in my case, the text is: start "" "C:\Program Files (x86)\Ranorex 5.4\terminate_iproxy.vbs".)

Save this file with the name “terminate_iproxy.bat”. Again, you can save this file wherever you’d like; I saved mine in the same directory as the .vbs file.

3. Creating a reference to the .bat file in a Ranorex recording

Using “Add New Action”, add the following step to a Ranorex recording. It can either be part of an existing recording, or it can be its own standalone recording file, as in the example shown here:
end_iproxy_rec.JPG
When this action runs, if there are more than five instances of “iproxy.exe” running, they will all be terminated. For this reason, this action should only be placed at the end of a recording/test case/test suite as a cleanup (AKA teardown) step, rather than at the beginning.
You do not have the required permissions to view the files attached to this post.

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Processes not ending - memory leak?

Post by krstcs » Mon Dec 21, 2015 7:39 pm

Instead of creating an external batch or script file, you should just use .NET's built-in process management library and create a user-code module that kills the processes you want, placing it in the tear-down section of the test suite. Adding extra batch or script files makes editing and troubleshooting cumbersome and can lead to other issues such as the batch or script process being prematurely killed when the Ranorex test ends, even though it may not have finished killing all the rogue processes.

I use this method all the time with Java processes and it works great, you should be able to use if in your case:

Code: Select all

// add these to your using directives at the top of the file. If it fails on these, then you need to add them to your references in the project window.
using System.Diagnostics;
using System.Linq;

void ITestModule.Run() {
	Mouse.DefaultMoveTime = 300;
	Keyboard.DefaultKeyPressTime = 100;
	Delay.SpeedFactor = 1.0;

	List<string> processesToKill = new List<string>();
	processesToKill.Add("java");  //replace these with your processes that need to be killed - I use a list because I have several.  It's easier to start this way than to re-build it later when you realize you actually need a list...  :D
	processesToKill.Add("javaws");
	processesToKill.Add("jp2launcher");

	Report.Info("KILL", "Checking if this is a VM...");
	if (Host.Local.MachineName.ToUpper().Contains("<VM Name Here>".ToUpper())) { //I only do this on my vms, you can leave this out if you don't need to worry about it
		foreach (string pToKill in processesToKill) {
			Report.Info("KILL", "VM found - Killing process for '" + pToKill + "'...");
			foreach (Process p in Process.GetProcessesByName(pToKill)) {
			//foreach (Process p in Process.GetProcessesByName(pToKill).Where((p) => !p.MainWindowTitle.Equals("Jenkins Slave"))) { // I use this to make sure I don't kill my Jenkins slave process, if you need to filter, this is one way to do it...
				Report.Info("KILL", string.Format("Killing process with pid:{0}...", p.Id));
				p.Kill();
			}
			
			Delay.Milliseconds(2500);
			
			Report.Info("KILL", "Checking for any remaining processes for '" + pToKill + "'...");
			if (Process.GetProcessesByName(pToKill).Any(p => !p.MainWindowTitle.Equals("Jenkins Slave"))) {
				Report.Failure("KILL", "Failed to close all all process for '" + pToKill + "'.");
			}
		}
	}

	Report.Info("KILL", "Finished...");
}
Doing it in code will allow you to keep track of any changes as well since you will automatically have them in your versioning system (which you ARE using, right??? :D ).


Hope this helps!
Shortcuts usually aren't...

Otter_T
Posts: 18
Joined: Mon Aug 31, 2015 5:33 pm

Re: Processes not ending - memory leak?

Post by Otter_T » Tue Dec 29, 2015 5:39 pm

Thank you, krstcs. I will definitely give this a try, because an entirely self-contained way to kill processes is exactly what I've been looking for.