locked
database unit test times out

    Soru

  • Does anyone know how to resolve the timeout issue with database unit tests? I've added a database unit test to my test solution and it should normally take about 5 minutes to run. I get this error within about 30 seconds:

     

    Test method dmReturns_Unit_Tests.ETL_Tests2.ETL_FactReturnCreditDetails threw exception:  System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding..

     

    I tried adding a .testconfig file to the solution and setting the timeout but that didn't work.

    I tried setting the timeout property in the test manager for the individual test but that didn't work.

    I tried setting the connectionstring to include a "connect timeout" property but that didn't work.

     

    Any help would be greatly appreciated.

    19 Ekim 2007 Cuma 22:40

Tüm Yanıtlar

  • There is a timeout parameter that you can set on the SqlCommand object.


    SqlCommand sqlComm = new SqlCommand();
    sqlComm.CommandTimeout = 60;

    The timeout value is in seconds. The default is 30 seconds. Setting this parameter to 0 will result in no timeout.

    24 Ekim 2007 Çarşamba 15:27
  • Thank you so much for the response. Although, I understand the two commands you show above, I don't quite understand where in the code to inject these commands. I'm using database unit tests that were generated by DB Pro. When I veiw the generated code, no where do I see this type of logic or a place to add this logic. Can you be more specific on how to do this with DB Pro unit tests? Thank you!

     

    24 Ekim 2007 Çarşamba 22:51
  • I'm having the same problem. I have about 5 different unit tests and two or three will succeed but the remaining will fail because of a time out.

    I tried
        - Increasing the timeout value for individual tests.
        - Increasing the registry values LongRunningQueryTimeoutSeconds and QueryTimeoutSeconds.
       
    The last option helped a little but I increase those values to 1000, which is longer than they need--assumming those values are in seconds. None of these allowed all tests to succeed though.

    The error message I get for the individual tests is

    Test method MyUnitTests.sMyProc.tMyTable_DeletedTest threw exception:  System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding..

    The stack trace

       at Microsoft.VisualStudio.TeamSystem.Data.UnitTesting.ExecutionEngine.ExecuteTest(ConnectionContext ctx, String testSql, DbParameter[] tsqlParameters)
       at Microsoft.VisualStudio.TeamSystem.Data.UnitTesting.DatabaseTestService.Execute(ConnectionContext scriptExecutionContext, ConnectionContext privilegedExecutionContext, DatabaseTestAction action, DbParameter[] sqlParameters)
       at
    MyUnitTests.sMyProc.tMyTable_DeletedTest() in C:\MyProjects\Client\db\MyUnitTests\ssMyProc.cs:line 77

    Thanks,

    Brian
    16 Ocak 2008 Çarşamba 14:27
  • Brian - did you create your tests as DB Unit tests? That's what I did.

     

    Moderator: is it possible to move our thread to the DB Pro forum? We are not getting any help resolving why DB Pro Unit Tests time out. I'm still experiencing the issue and have tried everything I can think of.

     

    Thanks!

    16 Ocak 2008 Çarşamba 15:59
  • Yes, I created them as DB Unit tests. Initially, the tests succeeded. After adding several unit tests, the new ones started failing with the timeout problem. I can run the tests individually without the timeout error but when I run them altogether is when they start failing.

    Thanks
    16 Ocak 2008 Çarşamba 23:40

  • I found that by adding CommandTimeout = 0 (no timeout) to the TestInitialize() method resolved this issue.

    [TestInitialize()]
            public void TestInitialize()
            {
                base.InitializeTest();
                this.ExecutionContext.CommandTimeout = 0;
            }


    Is the timeout value in the following code suppose to surved this purpose or am I mistaken? None of my tests require more than 2.5 minutes to finish.

    [Timeout(18000000), TestMethod()]
            public void MyTest()
            {
                DatabaseTestActions testActions = this.
    MyTestCode;
                // Execute the pre-test script
                ......

    17 Ocak 2008 Perşembe 19:44
  •  Brian Seelig wrote:

    I found that by adding CommandTimeout = 0 (no timeout) to the TestInitialize() method resolved this issue.

    [TestInitialize()]
            public void TestInitialize()
            {
                base.InitializeTest();
                this.ExecutionContext.CommandTimeout = 0;
            }

     

    Hi Brian,

     

    It seems I need to do something like the above as I have some tests that worked fine until I started data driving them.  Since then, inidividual tests arbitrarily fail (ie might pass this time and fail next time) with the same timeout message as the original poster.

     

    I tried to add the above [TestInitialize()] section to my test class, but wonder what type the test class is, or what it is derived from, as my 'this' does not contain a 'ExecutionContect'?  If I create a member of type ExecutionContext, the member does not contain a 'CommandTimeout'.

     

    I really though I had found a solution when I came into this thread, but now it appears to just add to my frustration.


    Is the timeout value in the following code suppose to surved this purpose or am I mistaken? None of my tests require more than 2.5 minutes to finish.

    [Timeout(18000000), TestMethod()]
            public void MyTest()
            {
                DatabaseTestActions testActions = this.
    MyTestCode;
                // Execute the pre-test script
                ......

     

    The Tiemout value above relates to the time it takes this entire individual test to run, whereas the timeout we are experiencing appears to be some sort of connection problem.  A timeout value can be placed in the connection string as well, which is also not solving this problem.

     

    Charlie

    29 Şubat 2008 Cuma 15:48
  • Hi Charlie,

    FYI: I'm still having the same problem actually; even after trying the solution I posted above. My tests usually fail but sometimes one will succeed while the others fail.
    01 Mart 2008 Cumartesi 04:48
  • Further information on this problem (is anyone from MS reading - this is apparently a common problem)...

     

    I notice with Reliability and Performance Monitor that the frequency of failure is much higher as the physical memory on the system runs low, and hard faults go up.

     

    I think the cause of the timeouts are therefore due to memory paging.

     

    When I run my tests as individual unit tests, they use little resource, but when data driven, the VSTestHost process gradually eats memory (my tests are not leaking - just not being garbage collected, apparently

     

    I can't inject any code at the context where the sql commands are issued, i just get the assemblies delivered, and there seems to be no way of overriding the default setting for command timeout from the management console.

     

    Perhaps we need to double the physical memory as a min requirement for Data driven UTF?

    06 Mart 2008 Perşembe 16:21
  • Increase the CommandTimeout attribute value in the app.config file. The default value is 30 seconds.

    ExecutionContext Provider="System.Data.SqlClient" ConnectionString="Data Source=<ServerName>;Initial Catalog=<DBName>;Integrated Security=True;Pooling=False" CommandTimeout="60" /> 

    PrivilegedContext Provider="System.Data.SqlClient" ConnectionString=<ServerName>;Initial Catalog=<DBName>;Integrated Security=True;Pooling=False" CommandTimeout="60" />

    16 Ocak 2012 Pazartesi 09:13