3
Vote

Chutzpah should not cause database connections to get open.

description

Matthew,

Frist and foremost, thank you for writing Chutzpah, it's been useful for me at my organization.

We have configured Chutzpah in one of your projects. The test cases are discovered and run just fine. We're also able to run code coverage on the project. However, we are getting "Object reference not set to an instance of an object" dialog errors from Visual Studio when opening our solution (see attached screenshot). I tracked down the problem to Chutzpah.

I'm attaching a minimal case that reproduces the problem.

Basically, if you have an Entity Framework connection string in the web.config file of a solution, Chutzpah will trigger a database connection when collecting the project's items.

I debugged over chutzpah code and found the source of the error, this is the interesting part of the call trace:
...
System.Data.SqlClient.SqlConnection.Open
    ...
Microsoft.VisualStudio.Data.Package.DataConnection.EnsureConnected
Microsoft.VisualStudio.Data.Package.DataExplorerNode.EnumerateOrRefreshChildren
...
Microsoft.VisualStudio.Data.Package.DataExplorerConnection.TryGetProperty
Microsoft.VisualStudio.Data.Package.DataExplorerConnection.Microsoft.VisualStudio.Shell.Interop.IVsHierarchy.GetProperty
VS11.Plugin.VsSolutionHelper.GetPropertyValue Line 84    <<<<<<<<<<<
VS11.Plugin.VsSolutionHelper.GetProjectItems Line 48
...
Chutzpah.VS2012.TestAdapter.ChutzpahTestContainerDiscoverer.FindPotentialTestFiles Line 376
Chutzpah.VS2012.TestAdapter.ChutzpahTestContainerDiscoverer.OnSolutionProjectChanged

It looks like the call to IVsHierarchy.GetProperty can cause database connections to get open when the project is using the Entity Framework.

If you try to open the minimal case you won't get the "Object reference not set to an instance of an object." errors, as I have cleaned the connection strings in the web.config file. But you should be seeing a "Connect to SQL Server" dialog instead. Also, if you debug Chutzpah and break on System.Data.SqlClient.SqlException, you should be getting one on the GetPropertyValue method of the VsSolutionHelper class in Chutzpah.


Also, please note that the minimal case solution can be opened without errors when you disable the Chutzpah Test Adapter plugin. We have found a work around, removing or commenting out Entity Framework's connection string in the web.config file avoids the errors to be thrown. So, fixing this is not urgent to us. However, it would be nice if Chutzpah stops triggering database connections.

Miguel

file attachments

comments

mmanela wrote Jun 30, 2014 at 3:14 PM

I tried to repro this with your sample in VS2013 but I did not get the error.

Does this still happen for you if you add a chutzpah.json file which specifies which are your test files?https://chutzpah.codeplex.com/wikipage?title=Using%20the%20tests%20setting&referringTitle=Chutzpah.json%20Settings%20File

MiguelIbarra wrote Jun 30, 2014 at 4:01 PM

Matthew,

Oh, yes. We get the error with a chutzpah.json file in place.

Note that getting the items from the project happens just before filtering them using the config file settings. So, not having a chutzpah.json file doesn't modify this problem:

In ChtuzpahTestContainerDiscoverer.cs 's FindPotentialTestFiles method:

1 return (from item in VsSolutionHelper.GetProjectItems(project)
2 let hasTestExtension = HasTestFileExtension(item)
3 let isChutzpahSettingsFile = fileProbe.IsChutzpahSettingsFile(item)
4 where !fileProbe.IsTemporaryChutzpahFile(item) && (hasTestExtension || isChutzpahSettingsFile)
                   select new TestFileCandidate
                    {
                        Path = item
                    }).ToList();
GetProjectITems in line 1 above is the call triggering the database connections, the config file will get used later on like 3.

I'm also using the Visual Studio Sql Server Data Tools extensions on my machine. That could be causing the problem for me and making it not reproducible on your machine.

is there a different way to get the list of files in a project without using IVsHierarchy.GetProperty on the VS API?

Thank you for looking at this!
Miguel

mmanela wrote Jun 30, 2014 at 4:40 PM

I am not sure about another way. What I am doing is a very standard way to enumerate the files.

mmanela wrote Sep 10, 2014 at 12:01 AM

I fixed this issue in commit: ec9e5b515dc9.