I also saw the tests fail when installing this, it certainly looks like
a timing issue as the third time I tried it worked.
However, I don't really like the idea of increasing the sleep time as it
makes my tests go quite slow, I've been playing with a patch along the
lines of the following:
--- a/lib/Net/LDAP/Server/Test.pm
+++ b/lib/Net/LDAP/Server/Test.pm
@@ -828,6 +828,8 @@ sub new {
"cannot handle both 'data' and 'auto_schema' features. Pick
one.";
}
+ pipe(my $r_fh, my $w_fh);
+
my $pid = fork();
if ( !defined $pid ) {
@@ -835,15 +837,18 @@ sub new {
}
elsif ( $pid == 0 ) {
+ warn "creating new LDAP server on port $port ... \n";
+
# the child (server)
my $sock = IO::Socket::INET->new(
Listen => 5,
Proto => 'tcp',
Reuse => 1,
LocalPort => $port
- );
+ ) or die "Unable to listen: $!";
- warn "creating new LDAP server on port $port ... \n";
+ syswrite $w_fh, "Ready\n";
+ undef $w_fh;
my $sel = IO::Select->new($sock);
my %Handlers;
@@ -884,16 +889,10 @@ sub new {
}
else {
- # the parent (client).
- # hesitate a little to account for slow fork()s since
- # sleep() is not strictly portable.
- #warn "starting nap at " . localtime() . "\n";
- my $wait = time() + 2;
- while ( time() < $wait ) {
- 1;
- }
-
- #warn "awake at " . localtime() . "\n";
+ # the parent (client), wait for the client to say it's ready
+
+ return unless <$r_fh> =~ /Ready/;
+
return bless( \$pid, $class );
}
i.e. use a pipe to tell the parent when it's ready, this also allows the
client to signal a failure to the parent.