TFS 2010 - Test Impact Analysis Series - Part 7–aka Writing a Custom Data Collector

3/20/2011


We left Part 6 with our registry changes to get impact analysis working, however we still needed to restart IIS manually in order to reset the test run.

I promised that I would investigate writing a custom Data Collector to do this for us, and here it is.

Here is a great MSDN article on How to: Create a Diagnostic Data Adapter.  I followed this and added the code we needed to restart IIS when the test run starts.

ServiceController iisService = new ServiceController("W3SVC");
                if (iisService.Status != ServiceControllerStatus.Stopped)
                {
                    iisService.Stop();
                    iisService.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromMilliseconds(15000));
                }
                iisService.Start();
                iisService.WaitForStatus(ServiceControllerStatus.Running,TimeSpan.FromMilliseconds(15000));

This is pretty self explanatory so I won’t go into the details.

Ok, now we have our adapter lets install it.  Back to MSDN – How to: Install a Custom Diagnostic Data Adapter.  We basically need to copy the adapter into the DataCollectors folder on both the test agent machine (the one running our website) and restart the test agent.

Once we do this we have another option in our TestSettings screen in MTM.

test settings

Make sure that this box is ticked.  Now lets run our test again.  When we hit run test in MTM the custom data collector should kick in and restart IIS on the server.  So lets do that and check the event log on the server.  Mine correctly shows two events (in the system log) – WWW Publishing Service stopping and starting.

Now we can look at the Application log and we should see some information from the Profiler.  Here it is:-

trace

The profiler has started.  To double check I have opened the W3Wp.exe process with Process Explorer to check the environment variables.  As we expected we have the  COR_PROFILER and COR_ENABLE_PROFILING variables set correctly.

We now run our tests and check the results in MTM.

results

Here we can see our test impact results have been generated!!  Double click this and we see:-

impactfigures

We have successfully captured TIA data!  The final check is on the server.  Go back and look at the application log again.  We need to ensure that the profiler is being shutdown.  Sure enough here we see:-

profileroff

Success!!  We now have well functioning TIA data with remote IIS.

3/20/2011

No comments :

Post a Comment