Skip to content
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

Random port assignment erroring during concurrency #70

Open
andrewkruse opened this issue Jun 2, 2023 · 1 comment
Open

Random port assignment erroring during concurrency #70

andrewkruse opened this issue Jun 2, 2023 · 1 comment
Labels
bug good first issue Good issue to get started with the project

Comments

@andrewkruse
Copy link

andrewkruse commented Jun 2, 2023

Proposal

When a bunch of stuff is going on at the same time on a computer, the random port assignment fails because it is being taken. Instead of using python to find a random port and then launching the java server on it, perhaps make the java server bind a random port and pull that back up.

The lines in question:
https://github.com/wiremock/python-wiremock/blob/master/wiremock/server/server.py#L116-L121

My work around is essentially putting that _get_free_port in a loop until something succeeds...

Reproduction steps

On GitHub actions I have two pipelines that run concurrently with Wiremock. The port assignment fails -- it's already being reserved by something else by the time the java server comes up and runs.

References

My resolution in my testing looks something like this. Essentially try again for a bit so that two people standing it up at once don't fail.

@pytest.fixture()
def wiremock():
    initialized = False
    attempts = 0
    while attempts < 10 and not initialized:
        try:
            s = socket.socket(socket.AF_INET, type=socket.SOCK_STREAM)
            s.bind(("localhost", 0))
            address, port = s.getsockname()
            s.close()

            with WireMockServer(port=port) as wm:
                Config.base_url = 'http://localhost:{}/__admin'.format(wm.port)
                initialized = True
                yield wm
        except exceptions.WireMockServerNotStartedError as e:
            logging.error(e)
        attempts += 1
@andrewkruse andrewkruse added the bug label Jun 2, 2023
@mikeywaites
Copy link
Collaborator

@andrewkruse thanks for raising this issue. I think this could be supported natively within the WireMockServer class, we'd be more than happy to take a PR if you fancy having a go. Otherwise I will try and come to this soon. We are working on a bunch of new features to support different strategies for running the wiremock server like (#71) so it might be a little while before I get to it.

@oleg-nenashev oleg-nenashev added this to the WireMock Python 3.0 milestone Aug 29, 2023
@oleg-nenashev oleg-nenashev added the good first issue Good issue to get started with the project label Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue Good issue to get started with the project
Projects
None yet
Development

No branches or pull requests

3 participants