DotMemory error (comparing snapshot to itself)

171 Views Asked by At

Attempting to do some memory leak checks in my automation test using the following

  • nUnit 3.8.1
  • TestStack.White 0.13.3
  • dotMemory 3.0.20171219.105559

Launching my tests with the following console command, as outlined here.

dotMemoryUnit.exe "E:\nunit3-console.exe" -- "C:\Dev\White\bin\Debug\Automation.dll"

The tests (outlined below in mostly psuedocode) launches the application, grabs a snapshot, navigates into various sub pages, returns to the base page, adn then gets another snapshot so I can do a compare for survived objects. The snapshot comparison is done using the method outlined here

private const MemoryCheckPoint snapshot1

[ OneTimeSetUp ]
public void SetUp()
{
    // launch application, hook up with teststack.white
    LaunchApplication();
}

[ Test, Order(1) ]
public void GetSnapshot()
{
    snapshot1 = dotMemory.Check();
}

[ Test, Order(2) ]
public void DoStuff()
{
    //Many tests like this that test navigation from this page
    //making sure controls work and values are returned as expected
}

[ Test, Order (3) ]
public void CheckMemory()
{
    dotMemory.Check(memory =>
    {
        // Compare two checkpoints
        Assert.That(memory.GetDifference(snapshot1).GetSurvivedObjects
            (where => where.Type.Is<string>()).ObjectsCount, Is.EqualTo(0));
    });
}

[ OneTimeTearDown ]
public void CloseWindow()
{
    Application.Close();
}

The idea is that if there are any UI elements that don't get disposed of due to events etc, this should pick them up as survived objects, and then I can manually repeat the test later to track down the source of the problem.

However when I run the tests using the dotmemoryunit.exe console I get the following error.

1) Error : White.Tests.MemoryCheck.System.ArguementException : You are trying to compare the snapshot with itself at JetBrains.dotMemoryUnit.Kernel.dotMemory.Api.GetDifference< Snapshot snapshot1, Snapshot snapshot2>

Considering they're definitely different snapshots, I cannot figure out why this is failing.

The reason I'm using the console runner is because, for some reason, when I try to run the automation tests using the resharper test runner, they don't run and it just returns Inconclusive : test not run

1

There are 1 best solutions below

3
On

By default dotMemory Unit works in context of the "Test", you can think about it like at the very beginning of the test method there is a call DotMemoryUnitController.TestStart and at the very end DotMemoryUnitController.TestEnd. All data are only valid inside one "Test".

You can switch off this behaviour by specifying --no-instrumentation command line parameter and calling DotMemoryUnitController.TestStart and DotMemoryUnitController.TestEnd manualy how described in this article