Permalink
Browse files

RT #83905: add more tests for whether port closes in stop()

  • Loading branch information...
1 parent e3f8e52 commit 8f52acac099a8982e7e8ae09f5c37df263404a4a @pkarman pkarman committed Mar 13, 2013
Showing with 32 additions and 1 deletion.
  1. +32 −1 lib/Net/LDAP/Server/Test.pm
@@ -936,6 +936,8 @@ blessed reference to the PID of the forked server.
=cut
+my %PORTS; # inside-out tracking of port-per-server
+
sub new {
my $class = shift;
my $port = shift || 10636;
@@ -1017,7 +1019,9 @@ sub new {
return unless <$r_fh> =~ /Ready/; # newline varies
close($r_fh);
- return bless( \$pid, $class );
+ my $self = bless( \$pid, $class );
+ $PORTS{"$self"} = $port;
+ return $self;
}
}
@@ -1057,9 +1061,36 @@ sub stop {
else {
warn "waitpid($pid, 0) worked" if $ENV{LDAP_DEBUG};
}
+ my $tries = 0;
+ while ( $server->port_is_open() ) {
+ warn "Waiting for port to close...\n";
+ sleep(1);
+ if ( $tries++ > 10 ) {
+ warn "Failed to determine that port closed. Giving up.\n";
+ last;
+ }
+ }
return $pid;
}
+=head2 port_is_open
+
+Returns IO::Socket::INET->new for the current server port.
+If the port is already in use, this is a false value.
+
+=cut
+
+sub port_is_open {
+ my $self = shift;
+ my $port = $PORTS{"$self"};
+ return IO::Socket::INET->new(
+ PeerAddr => '127.0.0.1',
+ PeerPort => $port,
+ Proto => 'tcp',
+ Type => SOCK_STREAM,
+ );
+}
+
=head1 AUTHOR
Peter Karman, C<< <karman at cpan.org> >>

0 comments on commit 8f52aca

Please sign in to comment.