help with WaitForValidLicense

Class library usage, coding and language questions.
User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3945
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

help with WaitForValidLicense

Post by odklizec » Wed Jun 05, 2013 3:08 pm

Hi folks,

I successfully integrated Ranorex with our Jenkins setup but I'm experiencing some difficulties with WaitForValidLicense method.

Currently, we have one floating Premium and one floating Runtime license. But because our Jenkins configuration uses two build&test slaves (oh man I feel like a slaveholder;)), we are sometimes short of available licenses. Before we buy some more licenses, I hoped to enhance my Ranorex tests with WaitForValidLicense check. Unfortuantely, it does not work for me. If both licenses are taken, the next Ranorex test started from Jenkins fails with "no suitable license was available" error (it does not wait for a free RX license and there is no output "No free RX license available." in console).

Here is my WaitForValidLicense implementation...

Program.cs
class Program : CodeModules.CommonFunctions
    {
    	public static xSpector.Repository repo = xSpector.Repository.Instance;
    	
    	[STAThread]
    	public static int Main(string[] args)
        {
            Keyboard.AbortKey = System.Windows.Forms.Keys.Pause;
            int error = 0;
// check if Ranorex license is available (if not, wait for 15mins/check every 5secs)     
            Wait_For_Available_License(900000,5000);
            return error;
        }
    }
CommonFunction.cs
public static int Wait_For_Available_License(int WaitForLicenseTimeout, int WaitForLicenseInterval)
		{
			bool RXLicenseAvailable = Ranorex.Core.ElementEngine.WaitForValidLicense(new Ranorex.Duration( WaitForLicenseTimeout), new Ranorex.Duration(WaitForLicenseInterval));
                if (RXLicenseAvailable)
                {
                    System.Console.WriteLine("RX license avaliable!");
                    return 1;
                    
                }
                else
                {
                    System.Console.WriteLine("No free RX license available.");
                    return 0;
                }
		}
Does anyone see an error in this WaitForValidLicense implementation? Should I call it from somewhere else?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: help with WaitForValidLicense

Post by Support Team » Thu Jun 06, 2013 3:12 pm

Hello,

The following line in your code is placed before you call the method "Wait_For_Available_License()".
public static xSpector.Repository repo = xSpector.Repository.Instance;
You already need a license at this point.
Please try to call "WaitForValidLicense()" before you call the Ranorex Repository.
Thank you!

Regards,
Bernhard
.
Image

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3945
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: help with WaitForValidLicense

Post by odklizec » Fri Jun 07, 2013 8:45 am

Hi Bernhard,

Thanks for the hint! I knew I must have it in a wrong order ;)

However, it seems it's not the only problem! I changed the code, according your suggestion, and it now works. Unfortuantely, only in Debug build! It still fails in Release mode.

Please see try the attached screenshot...
tes_release_debug.png
tes_release_debug.png (30.13 KiB) Viewed 1641 times
In the debug build, I'm getting the information about available license. And if the license is not available (at a time of run), the test correctly waits and then throws a message about not available license (both to console and report).

In release mode, there is no info about the license availability and if the license is not available, the test immediatelly fails. As if the Wait_For_Available_License function is not called.

Please examine the attached test project...
Attachments
test.zip
(11.17 KiB) Downloaded 226 times
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3945
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: help with WaitForValidLicense

Post by odklizec » Mon Jun 10, 2013 9:52 am

Hi folks,

Is there anyone who successfully implemented WaitForValidLicense (in a similar way I'm trying to use)? Thanks in advance!
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: help with WaitForValidLicense

Post by Support Team » Mon Jun 10, 2013 10:17 am

odklizec wrote:In release mode, there is no info about the license availability and if the license is not available, the test immediatelly fails. As if the Wait_For_Available_License function is not called.
Then this seems to be a problem in your code, the Ranorex libraries do not change for debug or release builds.

I had a look on your code and the problem could be that you assume the static variables are initialized one after the other. With Release mode that might not be the case as the code gets optimized. Please, remove the static "repo" and "LicCheck" instances (or initialize them in the "Main" method, not directly) and call the "Wait_For_Available_License" function as first line in the "Main" method.

Regards,
Alex
Ranorex Team
.
Image

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3945
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: help with WaitForValidLicense

Post by odklizec » Mon Jun 10, 2013 1:46 pm

Hi Alex,

Thanks for the reply. It was really the code optimization that caused my problem in release build! I reorganized the code as per suggestion and now it works OK. Thanks again both you and Bernhard!

Just one more question. Is there a command to release stale licenses (even from command prompt)? I noticed that from time to time, licenses remain locked despite the tests already finished. And waiting for free license does not always help. So it would be nice to have a "manual" command to release stale licenses. Please take it as a feature request if there is no such feature right now. Thanks!
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: help with WaitForValidLicense

Post by Support Team » Wed Jun 12, 2013 11:23 am

Hi,

There is no such command.
The license is locked when the network connection to the machine where the license is used get lost or when Ranorex is closed unexpectedly.
After some minutes the locked license should be automatically freed again.
What do you mean with "waiting for free license does not always help", how long did you wait for the license to be freed again?

Regards,
Markus
.
Image

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3945
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: help with WaitForValidLicense

Post by odklizec » Wed Jun 12, 2013 12:00 pm

Hi Markus,

Well, in some cases, I simply need to restart the VM (XP 32/64) to "unlock" the license. It does not happen always or too frequently, so it's hard to track down the cause of this issue. I always examine the process manager but in most cases, there is no trace of still running Ranorex process. So it must be something at the license manager side? And no, I'm not aware of unexpectedly terminated Ranorex process or lost network connection.

OK, I will keep an eye on this problem. In any case, it would be really nice to have a code/command line option to forcibly close/clean up the RX licenses.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: help with WaitForValidLicense

Post by Support Team » Thu Jun 13, 2013 4:29 pm

Hello,

Could you please try to verify processes with TCPView?
This tool gives a detailed overview about running processes using a network connection.
You could download it from Microsoft.

I forwarded your feature request internally to discuss a command line option to release a license.

Regards,
Markus (T)
.
Image

erikoss
Posts: 4
Joined: Mon Nov 04, 2013 1:26 am

Re: help with WaitForValidLicense

Post by erikoss » Mon Nov 04, 2013 2:04 am

Hi Markus,

Will the developers implement Ranorex.Core.ElementEngine.ReleaseLicense()?

I maintain a VB.Net application that runs Ranorex tests.
The application uses WaitForValidLicense() to check Ranorex is installed and has a license.

When the application is idle, e.g. It is not running tests, I need to release the license for other test staff to use.

I'm finding to license is not released (leased/locked) until 5 minutes or more, after my application is closed.

Thanks
Erik
Caterpillar Minestar

erikoss
Posts: 4
Joined: Mon Nov 04, 2013 1:26 am

Re: help with WaitForValidLicense

Post by erikoss » Thu Nov 07, 2013 10:04 pm

Update from emails:
Hi Markus,

To clarify, I am requesting a VB.Net/C# method to release the license after execution of all tests (a test suite) are finished.

Our application maintains/stores tests and runs them.
While you are maintaining the tests or updating test information, you don't want to be locking a license that another tester can use.

We have up to 15 Testers developing test automation with our Automation program.
Testers will spend most of their time creating test cases.
And much less time executing test cases.

As soon as a test is run, a license is locked until you close the Automation program.
So it means at some point of the work day, the license server needs 15 licenses to handle 15 testers.

If we could release the license after test execution, we could use a license server with 10 licenses.

It would be good design have a "AcquireLicense" function AND a "ReleaseLicense".
It would also be useful if your license server had a user configurable "no test running" timeout value.

I have thought of a work around which I could implement.
That is create another program to get a license.
The main program can then run it ("AcquireLicense"), then close it ("ReleaseLicense").

Hi Erik,

That’s right, the license will be released when the main program is closed.
I will forward the request but I cannot guarantee that it will be implemented.
It would help me to argue when you could describe a use case where such a ReleaseLicense method is necessarily needed J.

Kind regards,
Markus Ebner

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: help with WaitForValidLicense

Post by Support Team » Fri Nov 08, 2013 11:11 am

erikoss wrote:As soon as a test is run, a license is locked until you close the Automation program.
So it means at some point of the work day, the license server needs 15 licenses to handle 15 testers.
This is only true if you have one application/process sitting there just waiting to execute tests. I guess you have one test application that waits for some user input to start the tests, right?
If that's true, then you are correct and the Ranorex license is only released, when the application/process closes. BTW, that application also locks all DLLs referenced by it, i.e. while that application is running you cannot e.g. change recordings/repositories in your tests, either.

However, that's only part of the truth. Actually, .NET supports so-called AppDomains, which are basically separate memory spaces within a process. And the good thing is, you can load and unload such AppDomains while the process is still running. If the AppDomain is unloaded, all DLLs used by it will be freed and so will the Ranorex license.

So, what you can do to only use a Ranorex license whenever tests are running, is let those test run in a separate AppDomain. When the tests are finished and the AppDomain is unloaded, the Ranorex license and all referenced DLLs are freed.

Regards,
Alex
Ranorex Team
.
Image