question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception thrown randomly when testing.

See original GitHub issue

Im using xUnit and WebApplicationFactory to create a test server. I wrote some test. When I run all one or two randomly fails. Run again and they succeed.

Here is my exception:

Message: 
System.InvalidOperationException : Collection was modified; enumeration operation may not execute.

  Stack Trace: 
Enumerator.MoveNextRare()
Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
EndpointDefinition.<PostProcessors>b__139_0(IGlobalPostProcessor p)
WhereArrayIterator`1.MoveNext()
List`1.InsertRange(Int32 index, IEnumerable`1 collection)
EndpointDefinition.PostProcessors(IGlobalPostProcessor[] postProcessors)
<>c__DisplayClass0_0.<<Main>$>b__7(EndpointDefinition ep) line 58
MainExtensions.MapFastEndpoints(IEndpointRouteBuilder app, Action`1 configAction)
MainExtensions.UseFastEndpoints(WebApplication app, Action`1 configAction)
Program.<Main>$(String[] args) line 51
Program.<Main>(String[] args)
InvokeStub_Program.<Main>(Object, Object, IntPtr*)
MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
--- End of stack trace from previous location ---
DeferredHost.StartAsync(CancellationToken cancellationToken)
HostingAbstractionsHostBuilderExtensions.StartAsync(IHostBuilder hostBuilder, CancellationToken cancellationToken)
HostingAbstractionsHostBuilderExtensions.Start(IHostBuilder hostBuilder)
TraffiCaptureFactoryBase.CreateHost(IHostBuilder builder) line 47
WebApplicationFactory`1.ConfigureHostBuilder(IHostBuilder hostBuilder)
WebApplicationFactory`1.EnsureServer()
WebApplicationFactory`1.get_Services()

Any idea whats going wrong?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
dj-nitehawkcommented, Sep 16, 2022

@szekelymatyas that was actually helpful to find the culprit. thank you very much! fixed in v5.2.0-beta10

1reaction
szekelymatyascommented, Sep 9, 2022

Im using visual studio with xunit right know. But the problem has occured in rider too, if i remember correctly. Later im gonna pull de source, but right know i have a lot of think to do. The biggest problem is that its only happens 2-3 times in about 100. So im not sure how to reproduce it deterministicly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I simulate throwing an exception at random point of ...
1- Make a function called RandomException(); that throw exception if a random value is divisible by 3 otherwise it won't throw the exception....
Read more >
Assert an Exception Is Thrown in JUnit 4 and 5
In this quick tutorial, we'll be looking at how to test if an exception was thrown using the JUnit library.
Read more >
Testing Exceptions: Harder Than It Looks
Exceptions are one of the most complicated constructs in many languages. We'll look at several ways to test them.
Read more >
Why are JUnit tests throwing errors randomly (Java ...
There could be several reasons why JUnit tests are throwing errors randomly. Some possibilities include: **Inconsiste. Continue reading.
Read more >
ITestOutputHelper throws exception "There is no currently ...
Hi guys,. I can't figure out this problem.... I have a .NET Framework 4.7.2 xUnit Project to test our DataModel Objects: it counts...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found