Subject: | Race in t/02-create.t test |
The t/02-create.t can fail like this:
t/02-create.t ..
1..4
ok 1 - HTTP Server started
not ok 2 - Got CAPTCHA successfully
ok 3 - An object of class 'HTTP::Cookies' isa 'HTTP::Cookies'
ok 4 - Received cryptographic hash in cookie
# Failed test 'Got CAPTCHA successfully'
# at t/02-create.t line 39.
# 500
# Can't connect to localhost:13432 (Spojení odmítnuto)
# Looks like you failed 1 test of 4.
That happens under loaded machine when $mech->get_ok() on line 39 gets processed before the server starts listening on a TCP port.
This is because HTTP::Server::Simple::background() does:
sub background {
my $self = shift;
my $child = fork;
croak "Can't fork: $!" unless defined($child);
return $child if $child;
...
$self->run(@_); # should never return
exit; # just to be sure
}
so:
my $server = CAPCServer->new(PORT);
my $pid = $server->background;
returns before the TCP socket is listening.
Either HTTP::Server::Simple should provide a synchronization mechanism or the test should cycle until it TCP connection can be established.