Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have problem with the tests in HTTP-Server-Simple-0.44.

I am using:

This is setup_listener from HTTP-Server-Simple-0.44/lib/HTTP/Server/

sub setup_listener { my $self = shift; my $tcp = getprotobyname('tcp'); socket( HTTPDaemon, PF_INET, SOCK_STREAM, $tcp ) or croak "socket: + $!"; setsockopt( HTTPDaemon, SOL_SOCKET, SO_REUSEADDR, pack( "l", 1 ) ) or warn "setsockopt: $!"; bind( HTTPDaemon, sockaddr_in( $self->port(), ( $self->host ? inet_aton( $self->host ) : INADDR_ANY ) ) ) or croak "bind to @{[$self->host||'*']}:@{[$self->port]}: $!"; listen( HTTPDaemon, SOMAXCONN ) or croak "listen: $!"; }

When running some of tests, $self->host is undefined and the call to listen does not return (and sometimes get Windows 7 in blocked state). ($self->host with the value '' used by Plack does also not work.)

Adding this before bind is a workaround

$self->host('localhost') if ! defined $self->host; $self->host('localhost') if $self->host eq '';

Is this a bug in Windows or what is a proper solution?

Replies are listed 'Best First'.
Re: HTTP-Server-Simple-0.44 tests and undefined $self->host
by Corion (Pope) on Apr 07, 2011 at 09:15 UTC

    This is weird. In theory, HTTP::Server::Simple would call ->lookup_localhost, which should fix $host.

    There are two bug reports that sound somewhat similar to your problem, but at least one claims that changes similar to yours solved the problem. The tests in H:S:S assume that localhost will resolve (to a local address) - maybe on your machine, this is not the case? This would be very weird, but I'd still check.

      My knowledge of HTTP::Server::Simple is limited.

      What I can see, is lookup_localhost call by _default_run. This is done first after setup_listener is called.

Re: HTTP-Server-Simple-0.44 tests and undefined $self->host
by Anonymous Monk on Apr 07, 2011 at 13:26 UTC
    No, its a bug in the test suite, it doesn't specify localhost or but uses the default, which is, which is fine for the module but not for the test suite.

    If you don't have a personal firewall, windows will happily let you create an internet accessible webserver, which is why test suites need to specify localhost, you can't rely on secure linux semantics.

    I've even gone as far as to disable my internet net stop "dhcp client" when installing modules since my personal firewall broke.

    Here is what I used (apply with patch -p1 < thepatch.patch from within HTTP-Server-Simple--- directory)

    diff -ruN HTTP-Server-Simple-0.43/t/00smoke.t HTTP-Server-Simple-0.430 +1/t/00smoke.t --- HTTP-Server-Simple-0.43/t/00smoke.t 2008-02-15 09:37:12.0000000 +00 -0800 +++ HTTP-Server-Simple-0.4301/t/00smoke.t 2011-03-05 06:55:12.00000 +0000 -0800 @@ -2,7 +2,7 @@ use_ok(HTTP::Server::Simple); ok(HTTP::Server::Simple->can('new'), 'can new()'); -my $s= HTTP::Server::Simple->new(); +my $s= HTTP::Server::Simple->new();; $s->host(''); isa_ok($s,'HTTP::Server::Simple'); is($s->port(),8080,'Defaults to 8080'); is($s->port(13432),13432,'Can change port'); diff -ruN HTTP-Server-Simple-0.43/t/01live.t HTTP-Server-Simple-0.4301 +/t/01live.t --- HTTP-Server-Simple-0.43/t/01live.t 2010-04-02 09:53:07.00000000 +0 -0700 +++ HTTP-Server-Simple-0.4301/t/01live.t 2011-03-05 06:55:12.000000 +000 -0800 @@ -19,7 +19,7 @@ use base qw(HTTP::Server::Simple::CGI); sub setup_listener { - my $self = shift; + my $self = shift;; $self ->host(''); $self->SUPER::setup_listener(); sleep 2; } @@ -38,7 +38,7 @@ { - my $s=HTTP::Server::Simple::CGI->new($PORT); + my $s=HTTP::Server::Simple::CGI->new($PORT);; $s->host('127.0.0. +1'); $s->host("localhost"); my $pid=$s->background(); diag("started server PID='$pid'") if ($ENV{'TEST_VERBOSE'}); @@ -111,7 +111,7 @@ sub run_server_tests { my $class = shift; - my $s = $class->new($PORT); + my $s = $class->new($PORT);; $s ->host(''); is($s->port(),$PORT,"Constructor set port correctly"); my $pid=$s->background(); diff -ruN HTTP-Server-Simple-0.43/t/04cgi.t HTTP-Server-Simple-0.4301/ +t/04cgi.t --- HTTP-Server-Simple-0.43/t/04cgi.t 2010-02-04 12:23:19.000000000 + -0800 +++ HTTP-Server-Simple-0.4301/t/04cgi.t 2011-03-05 07:04:19.0000000 +00 -0800 @@ -5,12 +5,12 @@ plan tests => 23; my $PORT = 40000 + int(rand(10000)); -my $host = gethostbyaddr(inet_aton('localhost'), AF_INET); +$main::host = gethostbyaddr(inet_aton('localhost'), AF_INET) || 'loca +lhost'; my %methods=( - url => "url: http://$host:".$PORT, + url => "url: http://${main::host}:$PORT", path_info => 'path_info: /cgitest/path_info', - server_name => "server_name: $host", + server_name => "server_name: $main::host", server_port => 'server_port: '.$PORT, server_software => 'server_software: HTTP::Server::Simp +le/\d+.\d+', request_method => 'request_method: GET', @@ -18,12 +18,12 @@ ); my %envvars=( - SERVER_URL => "SERVER_URL: http://$host:".$PORT.'/', + SERVER_URL => "SERVER_URL: http://${main::host}:$PORT/" +, SERVER_PORT => 'SERVER_PORT: '.$PORT, REQUEST_METHOD => 'REQUEST_METHOD: GET', REQUEST_URI => 'REQUEST_URI: /cgitest/REQUEST_URI', SERVER_PROTOCOL => 'SERVER_PROTOCOL: HTTP/1.1', - SERVER_NAME => "SERVER_NAME: $host", + SERVER_NAME => "SERVER_NAME: $main::host", SERVER_SOFTWARE => 'SERVER_SOFTWARE: HTTP::Server::Simp +le/\d+.\d+', REMOTE_ADDR => 'REMOTE_ADDR:', QUERY_STRING => 'QUERY_STRING: ', @@ -31,7 +31,7 @@ ); { - my $server=CGIServer->new($PORT); + my $server=CGIServer->new($PORT);; $server->host( $main::host ); is($server->port(),$PORT,'Constructor set port correctly'); sleep(3); # wait just a moment @@ -132,7 +132,7 @@ use Env; sub handle_request { - my $self=shift; + my $self=shift;; $self->host($main::host ); my $cgi=shift;

      Thanks for the answer!

      There must also be a bug in listen. It should have returned with an indication of the error. It does not return and sometimes even puts the operating system in an in-stable state.

      I have tried to install modules using Strawberry-Perl and CPAN in Windows 7. Have had problems with the test suites in HTTP-Server-Simple, Test-TCP and some other modules. Test-TCP is used in the test of many modules. It uses fork and kill on the forked processes and often the tests are blocked and the installation must be restated. Kill on forked processes in Windows is unsafe and unpredictable.

      Why are there so many problems with the test suites using Windows? Are there too few, who installs modules in Windows using Strawberry-Perl and CPAN.

        Why are there so many problems with the test suites using Windows? Are there too few, who installs modules in Windows using Strawberry-Perl and CPAN.

        Yes, and not consulting perlport

Re: HTTP-Server-Simple-0.44 tests and undefined $self->host
by Corion (Pope) on Apr 08, 2011 at 11:48 UTC