|
From: <jgr...@us...> - 2003-07-13 04:01:38
|
Update of /cvsroot/popfile/engine/tests
In directory sc8-pr-cvs1:/tmp/cvs-serv29055/tests
Modified Files:
TestProxy.tst
Log Message:
Improved tests for the Proxy module
Index: TestProxy.tst
===================================================================
RCS file: /cvsroot/popfile/engine/tests/TestProxy.tst,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TestProxy.tst 13 Jul 2003 02:40:35 -0000 1.2
--- TestProxy.tst 13 Jul 2003 04:01:35 -0000 1.3
***************
*** 7,14 ****
--- 7,57 ----
# ---------------------------------------------------------------------------------------------
+ sub forker
+ {
+ pipe my $reader, my $writer;
+ my $pid = fork();
+
+ if ( !defined( $pid ) ) {
+ close $reader;
+ close $writer;
+ return (undef, undef);
+ }
+
+ if ( $pid == 0 ) {
+ close $reader;
+
+ use IO::Handle;
+ $writer->autoflush(1);
+
+ return (0, $writer);
+ }
+
+ close $writer;
+ return ($pid, $reader);
+ }
+
+ sub pipeready
+ {
+ my ( $pipe ) = @_;
+
+ if ( !defined( $pipe ) ) {
+ return 0;
+ }
+
+ if ( $^O eq 'MSWin32' ) {
+ return ( ( -s $pipe ) > 0 );
+ } else {
+ my $rin = '';
+ vec( $rin, fileno( $pipe ), 1 ) = 1;
+ my $ready = select( $rin, undef, undef, 0.01 );
+ return ( $ready > 0 );
+ }
+ }
+
use POPFile::Configuration;
use POPFile::MQ;
use POPFile::Logger;
use Proxy::Proxy;
+ use IO::Socket;
my $c = new POPFile::Configuration;
***************
*** 21,24 ****
--- 64,69 ----
$c->logger( $l );
+ $c->initialize();
+
$l->configuration( $c );
$l->mq( $mq );
***************
*** 52,57 ****
$sp->logger( $l );
$sp->initialize();
$sp->config_( 'port', 9999 );
test_assert_equal( $sp->start(), 1 );
! $sp->start_server();
--- 97,139 ----
$sp->logger( $l );
+ $sp->forker( \&forker );
+ $sp->pipeready( \&pipeready );
+
$sp->initialize();
$sp->config_( 'port', 9999 );
test_assert_equal( $sp->start(), 1 );
! test_assert( $sp->start_server() );
!
! # Now connect a socket to the proxy through which
! # we can test it
! my $client = IO::Socket::INET->new(
! Proto => "tcp",
! PeerAddr => 'localhost',
! PeerPort => 9999 );
! $sp->service();
!
! test_assert( defined( $client ) );
! test_assert( $client->connected );
!
! $sp->service();
! select( undef, undef, undef, 0.25 );
! $sp->service_server();
! select( undef, undef, undef, 0.25 );
!
! # Basic connectivity test tell the phony
! # server to send a message and we'll receive
! # it through the proxy, then send a message
! # and check that the phony server gets it
!
! $sp->send( "fromserver\n" );
! $sp->service_server();
! my $line = <$client>;
! test_assert_regexp( $line, 'fromserver' );
! print $client "toserver\n";
! select( undef, undef, undef, 0.25 );
! $sp->service_server();
! test_assert_regexp( $sp->received(), 'toserver' );
!
! close $client;
! $sp->stop_server();
! select( undef, undef, undef, 0.25 );
|