chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
My project is currently using Isolator 5.3.1.0 in 900+ tests with MSTest. When attempting to run a large group of them, we find that VSTestHost.exe is quickly burning through memory. Eventually, everything just grinds to a halt and we have to kill VSTestHost. I set up a little test to see what was going on:

public class EmptyClass
{
}

[TestClass]
public class MemoryTest
{
   [TestCleanup]
   public void Cleanup()
   {
      Isolate.CleanUp();
   }

   [TestMethod]
   public void TestEmpty()
   {
      for (int i = 0; i < 10000; i++)
      {
         EmptyClass empty = Isolate.Fake.Instance<EmptyClass>();
      }
   }

   [TestMethod]
   public void TestNothing()
   {
      for (int i = 0; i < 100000000; i++)
      {
         EmptyClass empty = new EmptyClass();
      }
   }

   [TestMethod]
   public void TestOther()
   {
      for (int i = 0; i < 50; i++)
      {
         OtherClass test = Isolate.Fake.Instance<OtherClass>();
      }
   }
}


Running TestEmpty slowly increases the memory usage, visible by a change roughly 100-300K every time the Windows Task Manager screen updates.

Running TestNothing does not increase the memory usage over time. VSTestHost.exe gets to about 80K and then stays there for the duration of the test.

Running TestOther (OtherClass is a fairly large class in my project) increases the memory usage by 4000-7000K every time the screen updates. Based on this, you can see why I limited the run to 50 times.

Is there some way to prevent this memory accumulation from happening?
asked by hils0015 (680 points)

6 Answers

0 votes
Hi,

This is actually the expected result.
Naturally the Isolator does take chunks of memory but the question is does this memory released at the end of the test once the Isolator cleanup code is executed?
In the test you posted the cleanup is done after the test method run.

In order to check this you should run the same test method multiply times and the test should be decorated with the Isolated attribute.

//run this test multiply times.
[TestMethod, Isolated]
public void TestEmpty()
{
    EmptyClass empty = Isolate.Fake.Instance<EmptyClass>();
}


It may be done with a macro that will copy the same test method multiply times.

:arrow: Note that using recursive fakes is more memory intensive than other fake defaults but the memory should be released once the isolator cleanup code is executed.

Please let me know if you have more questions on this issue.
answered by ohad (35.4k points)
0 votes
Hi

After re-reading my last post I think I did not explain myself clearly.

What I mean is this: The test you posted does not reflects what's really happening in a normal test run. Normally, you'll be cleaning up after each test - in your example you create thousands of fake objects without cleaning up. The memory allocated for fake objects is only released on cleanup.

Our guideline is to decorate test classes using Isolator with the [Isolated] attribute - this ensures that fake objects are cleaned up after each test is run.

Does the problem recur after running your tests with the [Isolated] attribute? If you want some recommendations on how to test this, let me know.
answered by ohad (35.4k points)
0 votes
Thanks for the responses.

What you're saying makes sense, but I don't know how to run a test multiple times. Is there a way to loop a single test?

I have found that the following test results in no additional memory overhead:
[TestMethod]
public void TestEmpty()
{
   for (int i = 0; i < 10000; i++)
   {
      EmptyClass empty = Isolate.Fake.Instance<EmptyClass>();
      Isolate.CleanUp();
   }
}


Based on that, I'd say the problem must be with MSTest itself, since Isolator is cleaning up after itself.
answered by hils0015 (680 points)
0 votes
Hi,

You can do it by using NUnit framework with the Repeat attribute.
Here is an example of running a test method 100 times:

[TestFixture, Isolated]
public class TestClass
{
    [Test]
    [Repeat(100)]
    public void Test()
    {
        var fake = Isolate.Fake.Instance<ClassToFake>();
    }
}


If you will run this test from VS using TestDriven.NET you should monitor the process "ProcessInvocation.exe"
If you are running from command line you should monitor nunit-console.exe
answered by ohad (35.4k points)
0 votes
I tried running the following code:

[TestFixture, Isolated]
public class TestingClass
{
   [TearDown]
   public void Cleanup()
   {
      Isolate.CleanUp();
   }

   [Test]
   [Repeat(500)]
   public void MyTest()
   {
      var fake = Isolate.Fake.Instance<ClassToFake>();
   }

}


It resulted in the memory usage climbing to 500MB. I tried raising the repeat number to 1000, and I had to kill it when the memory usage got above 900MB.

Any thoughts on what could be causing this?
answered by hils0015 (680 points)
0 votes
Hi,

This looks like a problem.
Lets take it offline, I'll send you mail from our support mailbox and we'll continue from there.
answered by ohad (35.4k points)
...