Comments (6)
@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.
Personally I think that the readiness endpoint would be best and more consistent with what others would expect (:
from mockaco.
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?
from mockaco.
@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.
- 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.
@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)
- Document usage as a middleware
- GUI HOT 3
- Optimize redundant mock scripts evaluation HOT 3
- Support M1 chips HOT 1
- Allows ErrorHandlingMiddleware to be disabled HOT 1
- Support git as a source of mock templates
- Improvements for use in integration tests HOT 4
- Question about features HOT 2
- Request matching on query string to return mocked GraphQL responses HOT 2
- Include request headers in verification endpoint HOT 4
- Fake.Person.FullName returning back same name on each item in the array HOT 2
- Support for External JSON File References in Mock Configurations HOT 1
- Mock being returned when there is an error in condition HOT 1
- Add end-to-end tests to a sample API
- Use YAML issue templates
- Improve code style analyzers HOT 1
- Include pull request workflow
- Move docs to a better place HOT 1
- Delay attribute won't work in some cases
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mockaco.