Skip to content

Running tests with ITestAction attributes leaks memory #3858

Description

@MatteS75

Running this example:


    [SomeTestAttr]
    [TestFixtureSource(nameof(FixtureArgs))]
    public class Tests1
    {
        private static object[] FixtureArgs = Enumerable.Range(0, 100)
            .Select(a => new object[] {$"a{a:000}"})
            .ToArray();

        public Tests1(string arg)
        {
        }

        [Test]
        public void Test1([Range(0, 10)] int x)
        {
            Thread.Sleep(100);
            Assert.Pass();
        }
    }

    public class SomeTestAttrAttribute : Attribute, ITestAction
    {
        private object _data = Enumerable.Range(0, 1000000).ToArray();
        
        public void BeforeTest(ITest test)
        {
        }

        public void AfterTest(ITest test)
        {
        }

        public ActionTargets Targets { get; }
    }
    

From what we can see new attributes are created for each fixture, but never released.

This example is using TestFixtureSource to create many fixtures, but from what we can see the behavior is the same with multiple fixture classes.

Activity

  1. stevenaw commented on Jun 26, 2022

    @stevenaw
    Member

    This may've been "fixed" in #4034 through the introduction of caching the attribute instances

  2. lahma commented on Feb 26, 2023

    @lahma
    Contributor

    The earlier cache only was effective against attributes on methods. Created #4300 to address caching of test level metadata.

  3. added this to the 4.0 milestone on Apr 11, 2023
  4. OsirisTerje commented on Apr 19, 2023

    @OsirisTerje
    Member

    Seems this has been done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions