Forum Discussion

LordXane's avatar
LordXane
New Contributor
13 years ago

Testing Mutex related processes

So we have two .Net applications that communicate via locking Mutex objects (the best way to communicate between processes I'm told, but it seems clunky, I'm open to suggestions).



I'd like to write an automated test that locks a Mutex (simulating what the second application would do) and checks if the first application responds properly. But I can't find any way to do that in Test Complete 8. JScript doesn't seem to have anything like C#'s Mutex class.



I was thinking maybe I could write a C# function and call it from JScript but it seems like all I can call from JScript is C#Script, which doesn't support the Mutex class either.



As a last resort I can create a whole C# app that the automated test runs and uses that to simulate locking the Mutex, but it seems like a clunky fizx. Any suggestions?



Thanks in advance!
  • AlexeyK's avatar
    AlexeyK
    SmartBear Alumni (Retired)

    Corby,


    You can use .NET assemblies in your test. See http://smartbear.com/support/viewarticle/11403/ for complete information.


    To create and lock a mutex, you can use the following code:



    // Create a new mutex

    var myMutex = dotNET.System_Threading.Mutex.zctor_3(false, "MyMutex");

    // Lock the mutex

    myMutex.WaitOne();


    If needed, unlock the mutex at the end of the test run:



    // Release mutex

    myMutex.ReleaseMutex();