evdb / HTTP-Async

process multiple HTTP requests in parallel without blocking
http://search.cpan.org/dist/HTTP-Async/lib/HTTP/Async.pm
8 stars 14 forks source link

Tests fail when port 8080 is already in use #4

Closed DrHyde closed 10 years ago

DrHyde commented 11 years ago

I noticed this when my Jenkins instance (running on port 8080) tried to install HTTP::Async, which is a dependency of the application I'm trying to test, but it wouldn't surprise me if I've sent CPAN-testers failure reports for it too because of the same thing, when I try to test it in multiple perl builds at the same time.

A quick n dirty fix would be to try to bind the HTTP::Server::Simple used for testing to 8080 but if that fails try 8081, then 8082, etc

I think it should be as simple as adding a new() method to TestServer.pm that is just a wrapper around SUPER->new(), but which after calling the parent constructor sets $self->port(...), tries to start, if not increments and repeat ad infinitum. you may want to then stop the server (leaving it configured with a known-good port) so that start_ok works - but maybe not, given that you're not actually testing the server but testing an async client.

evdb commented 11 years ago

I was sure that there was some module on CPAN that would give you a free port number to use - but can't seem to find it now, you don't happen to know of one do you...

I'll do the fix you suggest, and I'll switch the test port to be '10000' or something that is much less likely to already be in use.

DrHyde commented 11 years ago

I don't, but apparently if you try to bind to port 0 you'll get some random unused port. You can find out which with getsockname. See here: http://stackoverflow.com/questions/7531591/getting-unused-port-number-in-c-dynamically-when-running-server-process

and here: http://www.perlmonks.org/?node_id=579649

evdb commented 11 years ago

Hopefully fixed in v0.11 which is going out to CPAN now. Please close this ticket when it works for you.

In the end I just picked oddball high ports, trying to test if the port was available became such a pain, and arguably should be something that the test server modules should do for me :)

DrHyde commented 11 years ago

Yup, WFM. I'll see if I can come up with a module for finding an unused port for a more robust solution to the problem later.

evdb commented 11 years ago

Solve this properly, using https://metacpan.org/module/Test::TCP#empty_port as spotted by the eagle eyed @DrHyde :)

kaoru commented 10 years ago

Finally fixed for real at https://github.com/evdb/HTTP-Async/commit/c8e0f4fb1441fb21af8506dd4e41d42374eb59a2!

Build Status