Skip to content

Commit

Permalink
Moved the start_server and find_port routines to a separate file so t…
Browse files Browse the repository at this point in the history
…hat they

can be used by other tests. Had to include use of File::Spec to portable read
them in under Test::Harness.
  • Loading branch information
rjray committed Jan 27, 2002
1 parent d77603c commit 792029b
Showing 1 changed file with 7 additions and 42 deletions.
49 changes: 7 additions & 42 deletions t/40_server.t
Expand Up @@ -5,23 +5,26 @@
use strict;
use subs qw(start_server find_port);
use vars qw($srv $res $bucket $child $parser $xml $req $port $UA @API_METHODS
$list $meth @keys %seen);
$list $meth @keys %seen $dir);

use File::Spec;
use Test;

use IO::Socket;
use LWP::UserAgent;
use HTTP::Request;

use RPC::XML::Server;
use RPC::XML::Parser;
require RPC::XML::Server;
require RPC::XML::Parser;

BEGIN { plan tests => 40 }

@API_METHODS = qw(system.identity system.introspection system.listMethods
system.methodHelp system.methodSignature system.multicall
system.status);

(undef, $dir, undef) = File::Spec->splitpath($0);
require File::Spec->catfile($dir, 'util.pl');

# The organization of the test suites is such that we assume anything that
# runs before the current suite is 100%. Thus, no consistency checks on
# any other classes are done, only on the data and return values of this
Expand Down Expand Up @@ -400,41 +403,3 @@ ok($res->{total_requests} == 21);
# Don't leave any children laying around
kill 'INT', $child;
exit;

sub start_server
{
my $S = shift;

my $pid;

if (! defined($pid = fork()))
{
die "fork() error: $!, stopped";
}
elsif ($pid)
{
return $pid;
}
else
{
$S->server_loop();
exit; # When the parent stops this server, we want to stop this child
}
}

sub find_port
{
my $start_at = $_[0] || 9000;

my ($port, $sock);

for ($port = $start_at; $port < ($start_at + 1000); $port++)
{
$sock = IO::Socket->new(Domain => AF_INET,
PeerAddr => 'localhost',
PeerPort => $port);
return $port unless ref $sock;
}

-1;
}

0 comments on commit 792029b

Please sign in to comment.