Skip to content

Cannot run tests in parallel because TypeLocator is using a static cache shared between tests #485

Closed
@idoban

Description

@idoban

Description

Cannot run concurrent tests using TestServer when using Auto Discovery to register types.

Staetup.cs
services.AddJsonApi(facade => facade.AddCurrentAssembly());

System.InvalidOperationException : Collection was modified; enumeration operation may not execute.
Stack Trace:
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at JsonApiDotNetCore.Graph.ServiceDiscoveryFacade.AddAssembly(Assembly assembly) in jsonapidotnetcore\src\JsonApiDotNetCore\Graph\ServiceDiscoveryFacade.cs:line 76

The root cause is due to
private static Dictionary<Assembly, List> _identifiableTypeCache = new Dictionary<Assembly, List>();

which is being concurrently updated by different tests (each starting up its own TestServer for tests isolation).

see:

private static Dictionary<Assembly, List<ResourceDescriptor>> _identifiableTypeCache = new Dictionary<Assembly, List<ResourceDescriptor>>();

Environment

  • JsonApiDotNetCore Version: 3.1.0
  • Other Relevant Package Versions:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions