-
Notifications
You must be signed in to change notification settings - Fork 352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: programmatic startup/shutdown improvements #422
Comments
@XVincentX check out gateway.helper in tests and admin.helper for admin server |
and config from code is not a problem gateway({config}) |
One issue here is that configuration is a global singleton. If you have multiple |
I’ve been looking to the helpers you provided and I realized that they’re basically miming somebody starting the gateway from the command line - and then throw some requests and wait the gateway to respond correctly in order to make sure it’s ready. My aim is more - let’s provide a builtin mechanism to start and stop the gateway, and I’ve started look into this. It turns out we can do that kind of easily. I've been playing around with a branch here: The idea is - instead of returning Same goes with an eventual Although we have that singleton problem right now, it can be tamed with a correct usage of //cc @kevinswiber What do you guys think? |
@kevinswiber this is why config is no just a parameter for gateway and for admin @XVincentX here is this part implemented for admin please do not join it with gateway. it is common you need only one of those for gateway and yes it can subscribe to http-ready instead of doing 25times request and waiting for 404 There is alternative variant it is actually closer to admin-helper. it can start\stop gateway. |
Also there are some complex but common scenarios Start fake backend (with request handler controlled by test) register policy (controlled by test) start eg, |
and one more thing:
this is no longer needed. you can pass the config directly to gateway.
|
Note to self — with the introduction of validation |
I'm curious if there are further plans for this in the near future or if it's going to be on the back-burner for a while? I asked this because I'm thinking about ways as a plugin developer to easily test plugins. With a bit of digging around in the source code, and seeing what patterns exist currently within the express-gateway/tests folder, I was able to figure out how to do what I'm thinking but it currently takes a fair amount of boilerplate code to do it. Could a set of test tools that essentially reduces that boilerplate be of value? |
Hey @jbalsip, So — we had several pull requests that improved the situation. There's still some work to do but we definitely want to get there. Right now I've been testing the plugins by putting You can see the relevant parts in the rewrite plugin: Plugin installation, starting the gateway from the CI server, sending Http request to the gateway It is not optimal, but so far has the best quality/time ratio. I have a plan for that, but before we have to clean up some technical debt we have in place (such as #610, for example); and then starting towards this road. Another item that is hurting EG's testability, for example, is the fact that it can't be initialised providing the configuration as a JSON Object (at least using the public API we offer). You're forced to provide a configuration path that means — files on the disk. I'm glad you brought you up this though. //cc @kevinswiber @altsang Maybe we can prioritise this item? What we can do right now — it's to document the process so that users do not feel lost like you are right now. |
@jbalsip nice work If we go as @XVincentX suggesting by putting express-gateway as a devDependency so in actual plugin test it will be just btw it doesn't have to be migration of all existing tests at once to new helpers. |
Thank you @DrMegavolt . I think having helpers and stub generators can go a long way in those efforts, and pretty much what I'd been envisioning with what I've been doing in the test tools repo. I did see what was done with the rewrite plugin but found when I tried out something that looked almost identical that it didn't quite work for me. I think circleci was trying to execute my tests while the gateway was still starting up. I might've missed some nuance in configuring but didn't have much chance to delve into that. So instead I started digging more into how the tests could control that more closely, and I've had fairly good results. Only drawback I've seen so far, aside from reducing the code it takes to do it, has been since the gateway is running in the same process as the tests that the console output will be mixed between gateway logging and test results. That's probably a whole other matter and perhaps out-of-scope for this particular issue, and I'm sure there's probably some way I can work around that somehow as well. At any rate, I'm certainly very interested in this and I'd be glad to help out as time allows. I'm actually trying to put together a rough proof of concept to demo to show my team sometime, but hard to say when that will be ready. |
Please keep us posted on that. We'll try to have an internal discussion as well and see if we can invest some time in test helpers. Thanks again! |
@jbalsip express-gateway/lib/plugins.js Line 65 in ca7b7af
in plugin context a logger is passed. a special one for plugins. so logs will not be mixed or use some lib like +1 to see the tests from your PoC Our current helpers cover scenarios of running EG in the same process and as a separate process (looks ugly but seems to work) Feel free to make small PRs with helpers as you see it. At some point the picture of helpers will be more or less complete so we document the approach as beta feature on the EG.io site and in the release notes. I believe feedback from others will follow, so the helpers can be improved and moved out of beta status. beta is mostly to avoid migration issues. One can always reference specific version of EG in their plugin and do migration in there own pace. Thanks! |
That is very helpful @DrMegavolt and thank you. I'll be sure to incorporate that into what I'm working on. |
While writing integration tests for plugin I wish I had 3 main features in the gateway:
gatewayInstance.close().then(()=>console.log("It's over"));
run
method might return a PromisegatewayInstance.run().then(()=>console.log("Time to proxy requests"));
The text was updated successfully, but these errors were encountered: