quarkiverse / quarkus-wiremock

Quarkus extension for launching an in-process Wiremock server
https://wiremock.org/
Apache License 2.0
15 stars 8 forks source link

Add support for random port allocation #68

Closed oleg-nenashev closed 6 months ago

oleg-nenashev commented 7 months ago

The extension often fails in the test when trying to allocate a port from higher or lower range, It would be nice if the extension could pick a random free port on startup, e.g. when random passed in the configuration

Sample output

....
Caused by: io.quarkus.runtime.QuarkusBindException: Port(s) already bound: 8081: Address already in use: bind
 at io.quarkus.vertx.http.runtime.VertxHttpRecorder$11.handle([VertxHttpRecorder.java:737](vscode-file://vscode-app/c:/Users/Oleg/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at io.quarkus.vertx.http.runtime.VertxHttpRecorder$11.handle([VertxHttpRecorder.java:718](vscode-file://vscode-app/c:/Users/Oleg/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at io.vertx.core.impl.future.FutureImpl$3.onFailure([FutureImpl.java:153](vscode-file://vscode-app/c:/Users/Oleg/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at io.vertx.core.impl.future.FutureBase.emitFailure([FutureBase.java:75](vscode-file://vscode-app/c:/Users/Oleg/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at io.vertx.core.impl.future.FutureImpl.tryFail([FutureImpl.java:230](vscode-file://vscode-app/c:/Users/Oleg/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
 at io.vertx.core.impl.future.Mapping.onFailure([Mapping.java:45](vscode-file://vscode-app/c:/Users/Oleg/AppData/Local/Programs/Microsoft%20VS%20Code/resources/app/out/vs/code/electron-sandbox/workbench/workbench.html))
chberger commented 7 months ago

Thanks @oleg-nenashev for creating this issue. Could you please elaborate what you mean with it fails quite often? The extension tries to allocate a predefined static port. If this port is not free, then of course it will fail. The user can choose any arbitrary port which should not conflict with other services.

The random port allocation mechanism is something which is on our agenda, but not ranked that important.

oleg-nenashev commented 7 months ago

It's an RFE, so totally fine if it will not be implemented soon :) Quarkiverse - wide issue templates would be cool though

It depends on the operating system, but I got it a few times on high-range ports.

Apparently it also happens during live coding when service is reloaded, it seems there is a race condition on restart. It is not a huge deal but might confuse some users

chberger commented 7 months ago

It's an RFE, so totally fine if it will not be implemented soon :) Quarkiverse - wide issue templates would be cool though Yeah, I should define some templates ...

It depends on the operating system, but I got it a few times on high-range ports.

Apparently it also happens during live coding when service is reloaded, it seems there is a race condition on restart. It is not a huge deal but might confuse some users

Ah, this sounds bad. I've implemented your RFE with https://github.com/quarkiverse/quarkus-wiremock/pull/74. Would you like to take a look at it?

chberger commented 7 months ago

@oleg-nenashev : Thanks for your review. Would you like to test the code from main or are you waiting for a released version?

oleg-nenashev commented 7 months ago

I will try with Main and create a downstream PR so that there is an example, thanks!

On Mon, Nov 27, 2023 at 3:00 PM Christian Berger @.***> wrote:

@oleg-nenashev https://github.com/oleg-nenashev : Thanks for your review. Would you like to test the code from main or are you waiting for a released version?

— Reply to this email directly, view it on GitHub https://github.com/quarkiverse/quarkus-wiremock/issues/68#issuecomment-1827888801, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAW4RIAAKIJBPKZTW7IQAHLYGSMILAVCNFSM6AAAAAA7YUK5OCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRXHA4DQOBQGE . You are receiving this because you were mentioned.Message ID: @.***>

oleg-nenashev commented 7 months ago

https://github.com/wiremock/wiremock-quarkus-devservice-demo/pull/1 verifies that. Thanks for the patch!

chberger commented 6 months ago

Feature has been released with 1.1.0