Skip Menu |

This queue is for tickets about the Net-LDAP-Server-Test CPAN distribution.

Report information
The Basics
Id: 74426
Status: resolved
Priority: 0/
Queue: Net-LDAP-Server-Test

People
Owner: Nobody in particular
Requestors: nine [...] detonation.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: [patch] allow passing a socket instead of a port number
All tests in our test suite use Net::LDAP::Server::Test. To be able to run multiple tests in parallel and thus make use of multi core CPUs, each test file uses a random port number for the LDAP server. Of course with random numbers, port colissions can and do happen. To make tests more reliable it would be nice if the test file could open the listening socket (and retry if the port is already used) and pass this socket to Net::LDAP::Server. This capability is implemented in the attached patch. (patch is against the patched version from RT #74425)
Subject: socket.diff
commit f9be1892f6545676978732d02ab6028692230856 Author: Stefan Seifert <nine@detonation.org> Date: Thu Jan 26 14:26:53 2012 +0100 Allow an open socket to be passed instead of a port number diff --git a/lib/Net/LDAP/Server/Test.pm b/lib/Net/LDAP/Server/Test.pm index 596ef73..aad3dee 100644 --- a/lib/Net/LDAP/Server/Test.pm +++ b/lib/Net/LDAP/Server/Test.pm @@ -797,6 +797,8 @@ listing on I<port> and handling requests using Net::LDAP::Server. I<port> defaults to 10636. +I<port> may be an IO::Socket::INET object listening to a local port. + I<key_value_args> may be: =over @@ -846,10 +848,10 @@ sub new { } elsif ( $pid == 0 ) { - warn "Creating new LDAP server on port $port ... \n" if $ENV{LDAP_DEBUG}; + warn "Creating new LDAP server on port " . (ref $port ? $port->sockport : $port) . " ... \n" if $ENV{LDAP_DEBUG}; # the child (server) - my $sock = IO::Socket::INET->new( + my $sock = ref $port ? $port : IO::Socket::INET->new( Listen => 5, Proto => 'tcp', Reuse => 1, diff --git a/t/03-socket.t b/t/03-socket.t new file mode 100644 index 0000000..bd0143e --- /dev/null +++ b/t/03-socket.t @@ -0,0 +1,33 @@ +use Test::More tests => 2; + +use strict; +use warnings; +use Carp; + +use Net::LDAP; +use Net::LDAP::Server::Test; +use Net::LDAP::Entry; +use IO::Socket::INET; + +# +# these tests pulled nearly verbatim from the Net::LDAP synopsis +# + +my %opts = ( + port => '10636', + dnc => 'ou=internal,dc=foo', + debug => $ENV{PERL_DEBUG} || 0, +); + +my $host = 'ldap://localhost:' . $opts{port}; + +my $socket = IO::Socket::INET->new( + Listen => 5, + Proto => 'tcp', + Reuse => 1, + LocalPort => $opts{port}, +); +ok( my $server = Net::LDAP::Server::Test->new( $socket ), + "spawn new server with socket passed" ); + +ok( my $ldap = Net::LDAP->new( $host, %opts, ), "new LDAP connection" );
thanks. released as 0.12 on cpan.