From 792029b62f44c6020c841c0dc09caee3a7c1fd4b Mon Sep 17 00:00:00 2001 From: rjray Date: Sun, 27 Jan 2002 23:03:48 +0000 Subject: [PATCH] Moved the start_server and find_port routines to a separate file so that they can be used by other tests. Had to include use of File::Spec to portable read them in under Test::Harness. --- t/40_server.t | 49 +++++++------------------------------------------ 1 file changed, 7 insertions(+), 42 deletions(-) diff --git a/t/40_server.t b/t/40_server.t index f0efeed..1c3f530 100644 --- a/t/40_server.t +++ b/t/40_server.t @@ -5,16 +5,16 @@ 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 } @@ -22,6 +22,9 @@ BEGIN { plan tests => 40 } 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 @@ -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; -}