Skip to content

Regression in property injection #3958

Closed

Description

@seahurricanelemonade

Hi

I'm upgrading from 0.67.4 to 1.3.9. My tests are set up in a fashion as described in #3266 .

The class that initialises the Pulsar container is throwing an exception with the following details:

    Failed to inject properties for type 'TestFeature': Failed to inject properties for type 'PulsarBrokerHandlerTestWrapper': Failed to initialize data source of type 'PulsarTestContainer': Docker API responded with status code=InternalServerError, response={"message":"Get \"https://registry-1.docker.io/v2/\": EOF"}

Stack trace:    at TUnit.Engine.Services.DataSourceInitializer.InitializeDataSourceAsync(Object dataSource, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, CancellationToken cancellationToken)
   at TUnit.Engine.Services.DataSourceInitializer.EnsureInitializedAsync[T](T dataSource, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, CancellationToken cancellationToken)
   at TUnit.Engine.Services.PropertyDataResolver.ResolvePropertyDataAsync(PropertyInitializationContext context, DataSourceInitializer dataSourceInitializer, IObjectRegistry objectRegistry)
   at TUnit.Engine.Services.PropertyDataResolver.ResolvePropertyDataAsync(PropertyInitializationContext context, DataSourceInitializer dataSourceInitializer, IObjectRegistry objectRegistry)
   at TUnit.Engine.Services.PropertyInitializationOrchestrator.InitializeSourceGeneratedPropertyAsync(Object instance, PropertyInjectionMetadata metadata, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, ConcurrentDictionary`2 visitedObjects)
   at TUnit.Engine.Services.PropertyInitializationOrchestrator.InitializeSourceGeneratedPropertiesAsync(Object instance, PropertyInjectionMetadata[] properties, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, ConcurrentDictionary`2 visitedObjects)
   at TUnit.Engine.Services.PropertyInitializationOrchestrator.InitializeObjectWithPropertiesAsync(Object instance, PropertyInjectionPlan plan, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, ConcurrentDictionary`2 visitedObjects)
   at TUnit.Engine.Services.PropertyInjectionService.<>c__DisplayClass7_0.<<InjectPropertiesIntoObjectAsyncCore>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at TUnit.Core.PropertyInjection.PropertyInjectionCache.EnsureInjectedAsync(Object instance, Func`2 injectionFactory)
   at TUnit.Core.PropertyInjection.PropertyInjectionCache.EnsureInjectedAsync(Object instance, Func`2 injectionFactory)
   at TUnit.Engine.Services.PropertyInjectionService.InjectPropertiesIntoObjectAsyncCore(Object instance, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, ConcurrentDictionary`2 visitedObjects)
Stack trace:    at TUnit.Engine.Services.PropertyInjectionService.InjectPropertiesIntoObjectAsyncCore(Object instance, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, ConcurrentDictionary`2 visitedObjects)
   at TUnit.Engine.Services.PropertyInjectionService.RecurseIntoNestedPropertiesAsync(Object instance, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, ConcurrentDictionary`2 visitedObjects)
   at TUnit.Engine.Services.PropertyInjectionService.InjectPropertiesIntoObjectAsyncCore(Object instance, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, ConcurrentDictionary`2 visitedObjects)

This is only happening after updating the TUnit libraries. The image exists in the remote container registry.

Activity

  1. seahurricanelemonade commented on Nov 30, 2025

    @seahurricanelemonade
    Author

    Just upgraded to 1.3.13 and its revealed more:

    Message: 
    Failed to inject properties for type 'TestFeature': Docker API responded with status code=InternalServerError, response={"message":"Get \"https://registry-1.docker.io/v2/\": EOF"}
    
    Stack trace:    at Docker.DotNet.DockerClient.HandleIfErrorResponseAsync(HttpStatusCode statusCode, HttpResponseMessage response) in /_/src/Docker.DotNet/DockerClient.cs:line 516
       at Docker.DotNet.DockerClient.MakeRequestForRawResponseAsync(HttpMethod method, String path, IQueryString queryString, IRequestContent body, IDictionary`2 headers, CancellationToken token) in /_/src/Docker.DotNet/DockerClient.cs:line 331
       at Docker.DotNet.Models.StreamUtil.MonitorResponseForMessagesAsync[T](Task`1 responseTask, DockerClient client, CancellationToken cancel, IProgress`1 progress) in /_/src/Docker.DotNet/Endpoints/StreamUtil.cs:line 80
       at DotNet.Testcontainers.Clients.DockerImageOperations.CreateAsync(IImage image, IDockerRegistryAuthenticationConfiguration dockerRegistryAuthConfig, CancellationToken ct) in /_/src/Testcontainers/Clients/DockerImageOperations.cs:line 73
       at DotNet.Testcontainers.Clients.TestcontainersClient.PullImageAsync(IImage image, CancellationToken ct) in /_/src/Testcontainers/Clients/TestcontainersClient.cs:line 430
       at DotNet.Testcontainers.Clients.TestcontainersClient.RunAsync(IContainerConfiguration configuration, CancellationToken ct) in /_/src/Testcontainers/Clients/TestcontainersClient.cs:line 337
       at DotNet.Testcontainers.Containers.DockerContainer.UnsafeCreateAsync(CancellationToken ct) in /_/src/Testcontainers/Containers/DockerContainer.cs:line 493
       at DotNet.Testcontainers.Containers.DockerContainer.StartAsync(CancellationToken ct) in /_/src/Testcontainers/Containers/DockerContainer.cs:line 337
       at DotNet.Testcontainers.Containers.ResourceReaper.GetAndStartNewAsync(Guid sessionId, IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConfig, IImage resourceReaperImage, IMount dockerSocket, ILogger logger, Boolean requiresPrivilegedMode, TimeSpan initTimeout, CancellationToken ct) in /_/src/Testcontainers/Containers/ResourceReaper.cs:line 231
       at DotNet.Testcontainers.Containers.ResourceReaper.GetAndStartNewAsync(Guid sessionId, IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConfig, IImage resourceReaperImage, IMount dockerSocket, ILogger logger, Boolean requiresPrivilegedMode, TimeSpan initTimeout, CancellationToken ct) in /_/src/Testcontainers/Containers/ResourceReaper.cs:line 255
       at DotNet.Testcontainers.Containers.ResourceReaper.GetAndStartDefaultAsync(IDockerEndpointAuthenticationConfiguration dockerEndpointAuthConfig, ILogger logger, Boolean isWindowsEngineEnabled, CancellationToken ct) in /_/src/Testcontainers/Containers/ResourceReaper.cs:line 142
       at DotNet.Testcontainers.Clients.TestcontainersClient.RunAsync(IContainerConfiguration configuration, CancellationToken ct) in /_/src/Testcontainers/Clients/TestcontainersClient.cs:line 321
       at DotNet.Testcontainers.Containers.DockerContainer.UnsafeCreateAsync(CancellationToken ct) in /_/src/Testcontainers/Containers/DockerContainer.cs:line 493
       at DotNet.Testcontainers.Containers.DockerContainer.StartAsync(CancellationToken ct) in /_/src/Testcontainers/Containers/DockerContainer.cs:line 337
       at PulsarTestContainer.InitializeAsync() in PulsarTestContainer.cs:line 22
       at TUnit.Core.ObjectInitializer.GetInitializationTask(Object obj, IAsyncInitializer asyncInitializer, CancellationToken cancellationToken)
       at TUnit.Core.ObjectInitializer.InitializeAsync(Object obj, CancellationToken cancellationToken)
       at TUnit.Core.ClassDataSources.ResolveDataSourceValueSync(IDataSourceAttribute dataSource, DataGeneratorMetadata metadata, Int32 recursionDepth)
       at TUnit.Core.ClassDataSources.InjectPropertiesSync(Object instance, Type type, DataGeneratorMetadata dataGeneratorMetadata, Int32 recursionDepth)
       at TUnit.Core.ClassDataSources.Create(Type type, DataGeneratorMetadata dataGeneratorMetadata, Int32 recursionDepth)
       at TUnit.Core.ClassDataSources.Create(Type type, DataGeneratorMetadata dataGeneratorMetadata)
       at TUnit.Core.ClassDataSources.<>c__DisplayClass5_0`1.<Get>b__0(Type _)
       at TUnit.Core.Data.ThreadSafeDictionary`2.<>c__DisplayClass5_0.<GetOrAdd>b__0()
       at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
    --- End of stack trace from previous location ---
       at System.Lazy`1.CreateValue()
       at TUnit.Core.Data.ThreadSafeDictionary`2.GetOrAdd(TKey key, Func`2 func)
       at TUnit.Core.Data.ScopedDictionary`1.GetOrCreate(TScope scope, Type type, Func`2 factory)
       at TUnit.Core.TestDataContainer.GetGlobalInstance(Type type, Func`2 func)
       at TUnit.Core.ClassDataSources.Get[T](SharedType sharedType, Type testClassType, String key, DataGeneratorMetadata dataGeneratorMetadata)
       at TUnit.Core.ClassDataSourceAttribute`1.<>c__DisplayClass10_0.<GenerateDataSources>b__0()
       at TUnit.Core.DataSourceGeneratorAttribute`1.<>c__DisplayClass1_0.<GenerateDataSourcesAsync>b__0()
       at TUnit.Core.TypedDataSourceAttribute`1.<>c__DisplayClass5_0.<<GetDataRowsAsync>b__0>d.MoveNext()
    --- End of stack trace from previous location ---
       at TUnit.Engine.Services.PropertyDataResolver.ResolvePropertyDataAsync(PropertyInitializationContext context, DataSourceInitializer dataSourceInitializer, IObjectRegistry objectRegistry)
       at TUnit.Engine.Services.PropertyDataResolver.ResolvePropertyDataAsync(PropertyInitializationContext context, DataSourceInitializer dataSourceInitializer, IObjectRegistry objectRegistry)
       at TUnit.Engine.Services.PropertyInitializationOrchestrator.InitializeSourceGeneratedPropertyAsync(Object instance, PropertyInjectionMetadata metadata, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, ConcurrentDictionary`2 visitedObjects)
       at TUnit.Engine.Services.PropertyInitializationOrchestrator.InitializeSourceGeneratedPropertiesAsync(Object instance, PropertyInjectionMetadata[] properties, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, ConcurrentDictionary`2 visitedObjects)
       at TUnit.Engine.Services.PropertyInitializationOrchestrator.InitializeObjectWithPropertiesAsync(Object instance, PropertyInjectionPlan plan, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, ConcurrentDictionary`2 visitedObjects)
       at TUnit.Engine.Services.PropertyInjectionService.<>c__DisplayClass7_0.<<InjectPropertiesIntoObjectAsyncCore>b__0>d.MoveNext()
    --- End of stack trace from previous location ---
       at TUnit.Core.PropertyInjection.PropertyInjectionCache.EnsureInjectedAsync(Object instance, Func`2 injectionFactory)
       at TUnit.Engine.Services.PropertyInjectionService.InjectPropertiesIntoObjectAsyncCore(Object instance, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, ConcurrentDictionary`2 visitedObjects)
    
      Stack Trace: 
    PropertyInjectionService.InjectPropertiesIntoObjectAsyncCore(Object instance, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, ConcurrentDictionary`2 visitedObjects)
    PropertyInjectionService.InjectPropertiesIntoObjectAsync(Object instance, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events)
    TestInitializer.InitializeTest(AbstractExecutableTest test, CancellationToken cancellationToken)
    <<ExecuteTestInternalAsync>b__1>d.MoveNext()
    --- End of stack trace from previous location ---
    <<ExecuteTestInternalAsync>b__1>d.MoveNext()
    --- End of stack trace from previous location ---
    TimeoutHelper.ExecuteWithTimeoutAsync(Func`2 taskFactory, Nullable`1 timeout, CancellationToken cancellationToken, String timeoutMessage)
    <<ExecuteTestInternalAsync>b__0>d.MoveNext()
    --- End of stack trace from previous location ---
    RetryHelper.ExecuteWithRetry(TestContext testContext, Func`1 action)
    RetryHelper.ExecuteWithRetry(TestContext testContext, Func`1 action)
    TestCoordinator.ExecuteTestInternalAsync(AbstractExecutableTest test, CancellationToken cancellationToken)
    
  2. thomhurst commented on Nov 30, 2025

    @thomhurst
    Owner

    Can you try v1.3.15 ?

  3. seahurricanelemonade commented on Nov 30, 2025

    @seahurricanelemonade
    Author

    Same issue still. Is there a timeout for the properties to be initialised? Maybe that's whats happening?

     Failed to inject properties for type 'TestFeature': Failed to inject properties for type 'PulsarBrokerHandlerTestWrapper': Failed to initialize data source of type 'PulsarTestContainer': Docker API responded with status code=InternalServerError, response={"message":"Get \"https://registry-1.docker.io/v2/\": EOF"}
    
    Stack trace:    at TUnit.Engine.Services.DataSourceInitializer.InitializeDataSourceAsync(Object dataSource, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, CancellationToken cancellationToken)
       at TUnit.Engine.Services.DataSourceInitializer.EnsureInitializedAsync[T](T dataSource, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, CancellationToken cancellationToken)
       at TUnit.Engine.Services.PropertyDataResolver.ResolvePropertyDataAsync(PropertyInitializationContext context, DataSourceInitializer dataSourceInitializer, IObjectRegistry objectRegistry)
       at TUnit.Engine.Services.PropertyDataResolver.ResolvePropertyDataAsync(PropertyInitializationContext context, DataSourceInitializer dataSourceInitializer, IObjectRegistry objectRegistry)
       at TUnit.Engine.Services.PropertyInitializationOrchestrator.InitializeSourceGeneratedPropertyAsync(Object instance, PropertyInjectionMetadata metadata, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, ConcurrentDictionary`2 visitedObjects)
       at TUnit.Engine.Services.PropertyInitializationOrchestrator.InitializeSourceGeneratedPropertiesAsync(Object instance, PropertyInjectionMetadata[] properties, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, ConcurrentDictionary`2 visitedObjects)
       at TUnit.Engine.Services.PropertyInitializationOrchestrator.InitializeObjectWithPropertiesAsync(Object instance, PropertyInjectionPlan plan, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, ConcurrentDictionary`2 visitedObjects)
       at TUnit.Engine.Services.PropertyInjectionService.<>c__DisplayClass7_0.<<InjectPropertiesIntoObjectAsyncCore>b__0>d.MoveNext()
    --- End of stack trace from previous location ---
       at TUnit.Core.PropertyInjection.PropertyInjectionCache.EnsureInjectedAsync(Object instance, Func`2 injectionFactory)
       at TUnit.Core.PropertyInjection.PropertyInjectionCache.EnsureInjectedAsync(Object instance, Func`2 injectionFactory)
       at TUnit.Engine.Services.PropertyInjectionService.InjectPropertiesIntoObjectAsyncCore(Object instance, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, ConcurrentDictionary`2 visitedObjects)
    Stack trace:    at TUnit.Engine.Services.PropertyInjectionService.InjectPropertiesIntoObjectAsyncCore(Object instance, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, ConcurrentDictionary`2 visitedObjects)
       at TUnit.Engine.Services.PropertyInjectionService.RecurseIntoNestedPropertiesAsync(Object instance, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, ConcurrentDictionary`2 visitedObjects)
       at TUnit.Engine.Services.PropertyInjectionService.InjectPropertiesIntoObjectAsyncCore(Object instance, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, ConcurrentDictionary`2 visitedObjects)
    
      Stack Trace: 
    PropertyInjectionService.InjectPropertiesIntoObjectAsyncCore(Object instance, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events, ConcurrentDictionary`2 visitedObjects)
    PropertyInjectionService.InjectPropertiesIntoObjectAsync(Object instance, ConcurrentDictionary`2 objectBag, MethodMetadata methodMetadata, TestContextEvents events)
    TestInitializer.InitializeTest(AbstractExecutableTest test, CancellationToken cancellationToken)
    <<ExecuteTestInternalAsync>b__1>d.MoveNext()
    --- End of stack trace from previous location ---
    <<ExecuteTestInternalAsync>b__1>d.MoveNext()
    --- End of stack trace from previous location ---
    TimeoutHelper.ExecuteWithTimeoutAsync(Func`2 taskFactory, Nullable`1 timeout, CancellationToken cancellationToken, String timeoutMessage)
    <<ExecuteTestInternalAsync>b__0>d.MoveNext()
    --- End of stack trace from previous location ---
    RetryHelper.ExecuteWithRetry(TestContext testContext, Func`1 action)
    RetryHelper.ExecuteWithRetry(TestContext testContext, Func`1 action)
    TestCoordinator.ExecuteTestInternalAsync(AbstractExecutableTest test, CancellationToken cancellationToken)
    
  4. thomhurst commented on Nov 30, 2025

    @thomhurst
    Owner

    Can you give me a test setup to reproduce it?

  5. seahurricanelemonade commented on Nov 30, 2025

    @seahurricanelemonade
    Author
  6. thomhurst commented on Nov 30, 2025

    @thomhurst
    Owner

    Thanks! Takes a lil while to start for me, but ends up passing:

    Image

    It may be an issue with your machine? The error is Docker returning an error?

  7. seahurricanelemonade commented on Nov 30, 2025

    @seahurricanelemonade
    Author

    Hmm thats so strange. If I revert the TUnit version back to 0.67.4, it works again. I'll have a bit more of a play.

  8. seahurricanelemonade commented on Nov 30, 2025

    @seahurricanelemonade
    Author

    I've figured it out. The property injection happens before any 'BeforeTestSession' hooks can take place now, whereas previously the hooks ran before property injection.

    Ive changed my 'BeforeTestSession' hook to be 'BeforeTestDiscovery'.

  9. seahurricanelemonade commented on Dec 11, 2025

    @seahurricanelemonade
    Author

    @thomhurst - Testing the latest version as of now. Are there now retry attempts on property injection if an exception was thrown? I've spotted that my WebApplicationFactory keeps getting called to initialise before a static BeforeEveryTest hook runs and then eventually it initialises successfully because that hook executes as the WebApplicationFactory relies on that hook executing first.

  10. seahurricanelemonade commented on Dec 11, 2025

    @seahurricanelemonade
    Author

    Seems fixed by #4049

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

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