Share via


TFS 2010 Build - Controlling QtAgent32.exe (the test agent process) startup and termination from within Build workflow

TFS 2010 and the associated Testing infrastructure for Testing (aka Test Lab capabilities) are designed to work well together, because there are designed closely integrated with each other. In the design of the Test Agent process (QtAgent32.exe which runs on the Test Agent machine) there has been a lot of optimizations and efficiencies that went into it. The Agent is supposed to stay in the background, and run the tests on behalf of the user, collect the various results/data as specified in the Test Run configurations, and then wait for the next invocation from wherever it may come from and so on. Basically it is not started for each individual Test Run within a build. This should work for the majority of scenarios.

You might run into some odd situations such as the application under test (AUT) shows some unexpected behavior and you would desire to terminate the Agent process, from within your build workflow and then restart it. One of such an odd case is the AUT shows some unexpected behavior due to bugs in its own code – these could be come of the following.

  • Memory Leaks
  • Handle Leaks
  • Application hangs and does not terminate.

Note that in all of the above cases the Test Infrastructure is doing its job, but it is the AUT that is showing uncontrollable behavior. In such situations the ideal solution would be fix the AUT, but the nature of the fix might be so involved that it might take several days. However dev work has to go and cannot wait for this to occur- meaning building and testing have to still continue for the dev teams to make progress with their ongoing work. Hence the desire to terminate the QtAgent32.exe process on the fly and then restart it so as to continue with further activities from within the Build Workflow.

The following are the steps to do this:-

The way to do this is, to restart the test agent “service” after the test run is complete. The restart of the service will automatically trigger the restart of execution engine (ie QtAgent32.exe) as well. To do this restart, you should do the following: -

  • Ensure that the user who is attempting to restart is admin on the test agent box.
  • Use service controller manager commands to restart the test agent service. The exact commands are as follows: -

To stop the agent: - sc \\mymachine stop vsttagent

To start the agent: sc \\mymachine start vsttagent

The above steps are manual. Sometimes this might not suffice, as you would want to incorporate this into your Build workflow at the appropriate location in a scriptable fashion.

There is an activity called InvokeProcess in the Workflow that can be used to do this. The correct place to insert this InvokeProcess activity would be after a Test Run has completed.

In the Build Workflow, there are activities (either ExecuteRemoteTestRun in lab template or MSTest in default template) which executes the tests. When the activity is finished, then you can assume that test run has completed. So then you would just insert the InvokeProcess activity when either ExecuteRemoteTestRun OR MSTest returns from their own invocations. So within the InvokeProcess activity you would call the Service Control Manager (sc above) with the stop and start options in order to trigger a restart of the QtAgent32.exe.

Comments

  • Anonymous
    August 24, 2012
    Could you please elaborate little more on the mechanism of using InvokeProcess?

  • Anonymous
    August 25, 2012
    Hi Nobbir, InvokeProcess is a workflow activity that should be available within the workflow editing experience in Visual Studio. So if you load up your build workflow and then select the ToolBox in the IDE to see the various activities you can see or should be able to see the "InvokeProces" as one of the activities you can drag and drop into your build workflow. Ofcourse you should call it with the appropriate set of parameters for the Process (in this case the termination process ie the call to Service Control Manager - SC STOP <MACHINE> <PROCESNAME> ) to do the Agent termination. Thanks,
    Girish.