Fix waiting for the server to start in t/author/http-server.t
Dagfinn Ilmari Mannsåker [Fri, 24 May 2013 21:39:19 +0000 (22:39 +0100)]
Use Net::EmptyPort directly, since we don't need any of the actual
testing stuff from Test::TCP. This also lets us control the sleep
interval and retries, so we don't have to loop ourselves as well.

Net::EmptyPort started exporting wait_port in 1.27, but doesn't have a
$VERSION of its own, so declare the author dependency on Net::TCP 1.27.

Changes
Makefile.PL
t/author/http-server.t

diff --git a/Changes b/Changes
index ac27f9c..3c88749 100644 (file)
--- a/Changes
+++ b/Changes
@@ -11,6 +11,7 @@ TBA
     with event loops.
   - lets you access a psgix.io socket, if your server supports it, for manual
     handling of the client - server communication, such as for websockets.
+  - Fix waiting for the server to start in t/author/http-server.t
 
 5.90030 - 2013-04-12
   ! POSSIBLE BREAKING CHANGE: Removed Regexp dispatch type from core, and put
index f25c082..a37f617 100644 (file)
@@ -94,6 +94,7 @@ else {
 
 push(@author_requires, 'CatalystX::LeakChecker', '0.05');
 push(@author_requires, 'Catalyst::Devel', '1.0'); # For http server test
+push(@author_requires, 'Test::TCP', '1.27'); # ditto, ships Net::EmptyPort
 
 author_tests('t/author');
 author_requires(
index ead1cad..7f886ca 100644 (file)
@@ -5,7 +5,7 @@ use Test::More tests => 1;
 
 use File::Path;
 use FindBin;
-use Test::TCP;
+use Net::EmptyPort qw(wait_port empty_port);
 use Try::Tiny;
 use Plack::Builder;
 
@@ -96,10 +96,7 @@ if ($^O eq 'MSWin32') {
 sub wait_port_timeout {
     my ($port, $timeout) = @_;
 
-    # wait_port waits for 10 seconds
-    for (1 .. int($timeout / 10)) { # meh, good enough.
-        try { wait_port $port; 1 } and return;
-    }
+    wait_port($port, 0.1, $timeout * 10) and return;
 
     die "Server did not start within $timeout seconds";
 }