Giter VIP home page Giter VIP logo

Comments (6)

natenho avatar natenho commented on June 12, 2024 1

@Im5tu, glad to read that you find a way to proceed and yes, you are probably right, the scripting engine generates a little overhead to the loading time and can lead to some race condition if you're expecting mocks to be ready right after Mockaco is listening. Actually we don't have any readiness endpoint, it surely can be useful for scenarios like yours.

I'd be honored to be mentioned in your channel! I can be found as @natenho everywhere, although I'm not too much active on social media as you will notice ;-) Thank you

from mockaco.

Im5tu avatar Im5tu commented on June 12, 2024 1

Personally I think that the readiness endpoint would be best and more consistent with what others would expect (:

from mockaco.

natenho avatar natenho commented on June 12, 2024

Hi @Im5tu , could you help me understand your scenario? I'm not familiar with TestcontainersContainer, but I was able to test the regular hello demo using Docker like this:

Given hello.json in a given /Mocks directory in my host machine:

docker run -it --rm -p 5000:5000 -v $(pwd)/Mocks:/app/Mocks natenho/mockaco
$ curl -i http://localhost:5000/hello/test
HTTP/1.1 200 OK
Content-Type: application/json
Date: Mon, 26 Sep 2022 05:39:16 GMT
Server: Kestrel
Transfer-Encoding: chunked

{
  "id": "c4919955-b46f-1484-5552-f55b2ceab3da",
  "message": "Hello test!",
  "createdAt": "2022-09-26T05:39:16.2262442+00:00"
}

So I wonder if that might be something to do with your environment. Can you access the logs to check if Mockaco is properly loading your mock template like the screenshot below?

image

from mockaco.

Im5tu avatar Im5tu commented on June 12, 2024

@natenho - I think I've found the issue. Basically when the container starts the API is immediately available but the files haven't been mapped straight away. The immediate fix for me is to add a delay before allowing the tests to run, eg:

public async Task InitializeAsync()
{
    using var cts = new CancellationTokenSource(TimeSpan.FromMinutes(5));
    await _container.StartAsync(cts.Token);
    await Task.Delay(TimeSpan.FromSeconds(10));
}

It's strange that this only happens when there is a script section, assumingly because there is the templating taking a bit of time?

Is there an endpoint that I can call to check to see if everything is initialized at all? I didn't see one on a quick look around the repository. If there isn't, please could we add one or do the parsing before the API becomes available so we don't hit this timing issue?

Now that I've figured out the problem, I can continue the video I was going to do on this for my YT channel :)

Edit: Also, if you're present on Twitter, please can you let me know your handle so that I can link you to the video when it's available and direct others to follow you

from mockaco.

natenho avatar natenho commented on June 12, 2024
  • We can leverage Health checks in ASP.NET Core to add a readiness endpoint.
  • We could also provide an option to start listening only after all mock templates are loaded.

from mockaco.

natenho avatar natenho commented on June 12, 2024

@Im5tu the feature has been added to the last release ;) Check-out the docs at https://natenho.github.io/Mockaco/docs/health-checks/

from mockaco.

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.