PeakyTests / Peaky

Tests as a Service
Other
5 stars 8 forks source link

Peaky.ApplicationBuilderExtensions.UsePeaky is not threadsafe. #42

Closed TyOverby closed 6 years ago

TyOverby commented 6 years ago

Found while parallelizing tests:

<Message>System.InvalidOperationException : Collection was modified; enumeration operation may not execute.</Message>
          <StackTrace>   at System.ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion()
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at System.Linq.Enumerable.&lt;OfTypeIterator&gt;d__32`1.MoveNext()
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
   at Peaky.ApplicationBuilderExtensions.UsePeaky(IApplicationBuilder app)
   at MLS.Orchestrator.Startup.Configure(IApplicationBuilder app, IApplicationLifetime lifetime, IServiceProvider serviceProvider, IAntiforgery antiforgery, ILoggerFactory loggerFactory) in /home/tyoverby/workspace/trydotnet/orchestrator/MLS.Orchestrator/Startup.cs:line 242
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
   at Microsoft.Extensions.DependencyInjection.IServiceCollectionExtensions.InjectApiVersionRoutePolicy.&lt;&gt;c__DisplayClass2_0.&lt;Configure&gt;b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.Internal.AutoRequestServicesStartupFilter.&lt;&gt;c__DisplayClass0_0.&lt;Configure&gt;b__0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
   at Microsoft.AspNetCore.TestHost.TestServer..ctor(IWebHostBuilder builder, IFeatureCollection featureCollection)
   at MLS.Orchestrator.Tests.OrchestratorService.CreateTestServer(Action`1 configureServices, Action`1[] agents) in /home/tyoverby/workspace/trydotnet/orchestrator/MLS.Orchestrator.Tests/OrchestratorService.cs:line 46
   at MLS.Orchestrator.Tests.OrchestratorService..ctor(Action`1 configureServices, Action`1[] agents) in /home/tyoverby/workspace/trydotnet/orchestrator/MLS.Orchestrator.Tests/OrchestratorService.cs:line 35
   at MLS.Orchestrator.Tests.OrchestratorService..ctor(Action`1[] agents) in /home/tyoverby/workspace/trydotnet/orchestrator/MLS.Orchestrator.Tests/OrchestratorService.cs:line 29
   at MLS.Orchestrator.Tests.WorkspaceController_Specs.&lt;Compile_with_a_null_snippet_returns_bad_request&gt;d__0.MoveNext() in /home/tyoverby/workspace/trydotnet/orchestrator/MLS.Orchestrator.Tests/Workspace_Controller_Specs.cs:line 14
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()</StackTrace>
        </ErrorInfo>
      </Output>

Workaround: don't use this method in unit tests.

jonsequitur commented 6 years ago

Fixed by #43.