0
我們有幾個類似的單元測試都扔間歇OutOfMemoryExceptions,打破我們的CI管道:單元測試間歇OOM異常
public void Evaluate_Node1GreaterThanNode2_ReturnsTrue_Decimal()
{
//Arrange
var generator = _fixture.Create<Generator<decimal>>();
var value1 = _fixture.Create<decimal>();
var value2 = generator.Where(x => x < value1).First();
Node.Node1.Evaluate(Arg.Any<IPeriod>(), Arg.Any<IColleaguePeriodDataManager>()).Returns(value1);
Node.Node2.Evaluate(Arg.Any<IPeriod>(), Arg.Any<IColleaguePeriodDataManager>()).Returns(value2);
//Act
var result = Node.Evaluate();
//Assert
Assert.IsTrue(result);
Assert.IsTrue(Node.EvaluatedResult);
}
正如你可以看到我們使用AutoFixture的生成器來創建數字,大於/小於初始值:
generator.Where(x => x < value1).First();
很明顯,這種方法是行不通的。有人有工作嗎?
這裏的錯誤和堆棧跟蹤:
System.OutOfMemoryException : Array dimensions exceeded supported range.
at System.Collections.Generic.HashSet`1.SetCapacity(Int32 newSize, Boolean forceNewHashCodes)
at System.Collections.Generic.HashSet`1.AddIfNotPresent(T value)
at Ploeh.AutoFixture.RandomNumericSequenceGenerator.GetNextRandom()
at Ploeh.AutoFixture.RandomNumericSequenceGenerator.CreateRandom(Type request)
at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.Postprocessor`1.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.TracingBuilder.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.TerminatingWithPathSpecimenBuilder.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.RecursionGuard.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.RecursionGuard.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.Postprocessor`1.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.CompositeSpecimenBuilder.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.TracingBuilder.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.TerminatingWithPathSpecimenBuilder.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.RecursionGuard.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.Kernel.RecursionGuard.Create(Object request, ISpecimenContext context)
at Ploeh.AutoFixture.SpecimenFactory.Create[T](ISpecimenContext context, T seed)
at Ploeh.AutoFixture.SpecimenFactory.Create[T](ISpecimenContext context)
at Ploeh.AutoFixture.Generator`1.<GetEnumerator>d__2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)