Skip to content

Wrong work of IDisposeAsync on shared perAssembly class when injecting into another classDataSource #2507

@bazarniy

Description

@bazarniy

Sorry, I don't know did you see my comment here so I duplicate it as new issue

In 0.24 you've added property injection into ClassDataSource classes. Thank you very much!
But there are wrong dispose call in perAssembly shared class. Here is code structure:

[ClassDataSource<MyFactory>(Shared = SharedType.PerClass)]
[NotInParallel]
public class MyTests1(MyFactory factory)
{
    ...
}

[ClassDataSource<MyFactory>(Shared = SharedType.PerClass)]
[NotInParallel]
public class MyTests2(MyFactory factory)
{
    ...
}

public class MyFactory : IAsyncInitializer, IAsyncDisposable
{
    [ClassDataSource<MyServer>(Shared = SharedType.PerAssembly)]
    public required MyServer Server { get; init; }
    ...
}

public class MyServer : IAsyncInitializer, IAsyncDisposable
{
    ...
}

I run MyTests1 and MyTests2 in one session:

  • MyServer initializes 1 time (expected)
  • MyFactory initializes 2 times (expected)

When ONE test class finished:

  • MyFactory disposes 1 time (expected)
  • MyServer disposes 1 time (unexpected!)

Expected: MyServer.Dispose calls only after disposing all MyFactory classes

PS: when inject MyServer into test classes dispose works correctly

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions