Git Product home page Git Product logo

Comments (3)

GeraldLx avatar GeraldLx commented on September 26, 2024

I have no clue what you are trying to achieve, but the bug is not in AutoFixture but in your code.

There is no recursion in your classes Top/Bottom, so basically everything works like it should if you remove the addition of the behavior.

But lets assume your original problem is recursion, then your IsSeededRequestComparer is the problem. Basically you are saying that every SeededRequest is the same. So at the crash comes when a SeededRequest for Top is equal to a SeededRequest of Nullable.

Just change

  public ISpecimenBuilderNode Transform(ISpecimenBuilder builder)
  {
    return new RecursionGuard(builder, new OmitOnRecursionHandler(), new IsSeededRequestComparer(), Depth);
  }

to

  public ISpecimenBuilderNode Transform(ISpecimenBuilder builder)
  {
    return new RecursionGuard(builder, new OmitOnRecursionHandler(), Depth);
  }

and also everything works as expected.

from autofixture.

brian-knoll-micronetonline avatar brian-knoll-micronetonline commented on September 26, 2024

Thank you for responding

I have a 1000 or so classes that i am trying to generate. they are deeply nested and many of them have recursive loops. For my test i want to go 1 or 2 levels into the nesting when generating the top level class. With this level of nesting generating 1 class might take 20min or more. So, i am trying to limit the depth of generation. After applying the proposed solution from #1032 i ran into this issue but they did not mention the issue back then.

I will give this new info a try thank you.

from autofixture.

brian-knoll-micronetonline avatar brian-knoll-micronetonline commented on September 26, 2024

So, the code in my initial post does not work for me because certain types count for an additional level in the nesting counting. For example public int? NumberTwo {get;set;} counts one level for the Nullable and then one level for the int. so the int returns omitspecimen and then the nullable creation blows up. I hacked my way to something that works well enough for my purposes. I would not recommend using it as is but will hopefully help someone else.
I took the initial post from #1032 and modified the currentDepth calculation so that a nullable int would not get a nest increase. and would potentially work out.

int currentDepth = -1;
var seededRequest = (SeededRequest)request;
var requestsForCurrentThread = this.GetMonitoredRequestsForCurrentThread();
if (requestsForCurrentThread.Count > 0)
{
    int depthIncrease = 1;
    if (IsType(seededRequest.Request)
        && (IsNullableValue(seededRequest.Request) || IsValue(seededRequest.Request)))
    {
        depthIncrease = 0;
    }

    currentDepth = requestsForCurrentThread.Max(x => x.Depth) + depthIncrease;
}

but when i brought it over to my actual usage i had a bunch of issues with generic types like dictionaries where they would add a whole bunch of nesting levels to the counter. For example a dictionary is made up of keyvalue pairs which is made up of the actual type parameters. a that point i gave up and slapped a trycatch on the return and called it good enough.

else
{
    try
    {
        return this.Builder.Create(request, context);
    }
    catch (Exception)
    {
        return new OmitSpecimen(); // Hack
    }
}

from autofixture.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.