locked
Running All Tests - Out of Memory Exception RRS feed

  • Question

  • Hi all,

    Problem:

    Recently I started to face an issue on one of my project that contains around 650 unit tests.

    When I run all of them at once, some tests near the end of the unit test run start failing with a System.OutOfMemoryException.

    When I re-run the failing test again, they pass.

    Analysis:

    I looked at the task manager while running my test to see that the vstest.executionengine.x86.exe always increases until it reach 1330 MB of memory. Then the tests starts failing with the out of memory exception.

    Of course im sure that its possible that a few of my classes may have a memory leak, but 90% of my classes under test doesn't have such code that could lead to memory leaks.

    Many of my tests class doesn't have any TestInitialize or TestCleanup method since the creation of my classes are done directly inside the TestMethod test and since those classes under test doesn't implement IDiposable  (since there is no code that could lead to leaks).

    Questions:

    Now I am not sure what I may be doing wrong. But I'm wondering how come test objects remains in memory even after all the tests of a test class was run?

    have anyone experienced this or could point me to what I should do to fix or locate the problem?

    Thanks.

    Friday, January 8, 2016 3:59 PM

All replies

  • Hi SlickRickD,

    >>vstest.executionengine.x86.exe always increases until it reach 1330 MB of memory. Then the tests starts failing with the out of memory exception.

    What is your windows Environment, 32 bit or 64 bit? If you test it in other 64 bit machine, how about the result?

    Maybe it is related to the OS configuration like this case:

    http://stackoverflow.com/questions/14272768/getting-outofmemoryexception-in-unit-test

    Since you have many tests in the same solution, if possible, run few tests one time, for example, just run 100/200 tests, check it again.*

    Or you could create several ordered tests, and then add different tests to the ordered tests, and then ring the ordered test one by one.

    One tool here:

    http://blogs.msdn.com/b/calvin_hsia/archive/2012/06/27/10324809.aspx

    It could increase the memory available to our tests, maybe you could refer to it.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, January 11, 2016 7:21 AM
  • Hi Jack,

    im am sorry for the very later reply but I just didn't had the time to check this issue which is still pending.

    Im running the test in 32bit. I understand that running in 64 or tweak the test setting to give it more memory would probably delay the error a bit but I really don't understand why this is occurring.

    Shouldn't a test and its test objects be destroyed once a test (or at least the test class) was run?

    I do not understand why MSTest would keep all the test objects alive until all test classes was run?

    Should there be some logic to release tests that were completed and make them available to the GC?

    Friday, May 13, 2016 10:35 PM
  • I tried to put the following test cleanup in ALL my test classes but I am still getting an out-of-memory exception near the end of the tests.

    '''
    <TestCleanup>
    Public Sub TestCleanup()
        GC.Collect()
        GC.WaitForPendingFinalizers()
    End Sub

    Tuesday, May 17, 2016 7:09 PM
  • Hi SlickRickD,

    I think you viewed this thread before:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/95ac06fe-d595-4f49-b47a-bcdb667e65a1/out-of-memory-exceptions-while-running-tests?forum=vststest

    At least, we could know that the test framework really couldn't clean up the memory, since there are so many tests, maybe it really has the high requirement for the memory or others.

    Run it in a high configuration or the 64 bit machine is an idea I could get now, you could submit this feedback to Microsoft Connect feedback portal since I have no sample: http://connect.microsoft.com/VisualStudio/feedback/CreateFeedback.aspx,maybe the product team experts have good suggestions.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, May 19, 2016 9:38 AM