-
Notifications
You must be signed in to change notification settings - Fork 731
Description
Description
I'm getting random ArgumentOutOfRangeException from an internal StringBuilder.ToString() call when using object equivalency (Should().BeEquivalentTo) with large object graphs during concurrent test runs with xUnit:
Error Message:
System.ArgumentOutOfRangeException : Index was out of range. Must be non-negative and less than or equal to the size of the collection. (Parameter 'chunkLength')
Stack Trace:
at System.Text.StringBuilder.ToString()
at FluentAssertions.Equivalency.Tracing.StringBuilderTraceWriter.ToString()
at FluentAssertions.Equivalency.EquivalencyValidator.AssertEquality(Comparands comparands, EquivalencyValidationContext context)
at FluentAssertions.Collections.GenericCollectionAssertions`3.BeEquivalentTo[TExpectation](IEnumerable`1 expectation, Func`2 config, String because, Object[] becauseArgs)
at FluentAssertions.Collections.GenericCollectionAssertions`3.BeEquivalentTo[TExpectation](IEnumerable`1 expectation, String because, Object[] becauseArgs)
This only seems to occur sometimes when multiple tests are running concurrently. When run individually or sequentially, this error does not occur.
Is there any static or shared StringBuilder internally that might be used in overlapping test runs?
Reproduction Steps
This is difficult to reproduce in a controlled environment, since it only happens occasionally during concurrent test runs. It seems more likely to happen when evaluating large object graphs (depth > 15 or so) and only during concurrent test runs (xUnit concurrency settings "parallelizeAssembly": false)
Expected behavior
Not expecting an exception from StringBuilder.ToString()
Actual behavior
ArgumentOutOfRangeException
Regression?
No response
Known Workarounds
No response
Configuration
.NET 7
Fluent Assertions 6.12.0
xUnit 2.4.1
Other information
No response
Are you willing to help with a pull-request?
No