.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Net::Daemon::Test 3pm" .TH Net::Daemon::Test 3pm 2024-03-07 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Net::Daemon::Test \- support functions for testing Net::Daemon servers .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 7 \& # This is the server, stored in the file "servertask". \& # \& # Create a subclass of Net::Daemon::Test, which in turn is \& # a subclass of Net::Daemon \& use Net::Daemon::Test (); \& package MyDaemon; \& our @ISA = qw(Net::Daemon::Test); \& \& sub Run { \& # Overwrite this and other methods, as you like. \& } \& \& my $self = Net::Daemon\->new(\e%attr, \e@options); \& eval { $self\->Bind() }; \& if ($@) { \& die "Server cannot bind: $!"; \& } \& eval { $self\->Run() }; \& if ($@) { \& die "Unexpected server termination: $@"; \& } \& \& \& # This is the client, the real test script, note we call the \& # "servertask" file below: \& # \& # Call the Child method to spawn a child. Don\*(Aqt forget to use \& # the timeout option. \& use Net::Daemon::Test (); \& \& my($handle, $port) = eval { \& Net::Daemon::Test\->Child(5, # Number of subtests \& \*(Aqservertask\*(Aq, \*(Aq\-\-timeout\*(Aq, \*(Aq20\*(Aq) \& }; \& if ($@) { \& print "not ok 1 $@\en"; \& exit 0; \& } \& print "ok 1\en"; \& \& # Real tests following here \& ... \& \& # Terminate the server \& $handle\->Terminate(); .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This module is a frame for creating test scripts of Net::Daemon based server packages, preferrably using Test::Harness, but that's your choice. .PP A test consists of two parts: The client part and the server part. The test is executed by the child part which invokes the server part, by spawning a child process and invoking an external Perl script. (Of course we woultn't need this external file with \fBfork()\fR, but that's the best possibility to make the test scripts portable to Windows without requiring threads in the test script.) .PP The server part is a usual Net::Daemon application, for example a script like dbiproxy. The only difference is that it derives from Net::Daemon::Test and not from Net::Daemon, the main difference is that the \fBBind\fR method attempts to allocate a port automatically. Once a port is allocated, the number is stored in the file "ndtest.prt". .PP After spawning the server process, the child will wait ten seconds (hopefully sufficient) for the creation of ndtest.prt. .SH "AVAILABLE METHODS" .IX Header "AVAILABLE METHODS" .SS "Server part" .IX Subsection "Server part" .IP Options 8 .IX Item "Options" Adds an option \fB\-\-timeout\fR to Net::Daemon: The server's Run method will die after at most 20 seconds. .IP Bind 8 .IX Item "Bind" (Instance method) This is mainly the default Bind method, but it attempts to find and allocate a free port in two ways: First of all, it tries to call Bind with port 0, most systems will automatically choose a port in that case. If that seems to fail, ports 30000\-30049 are tried. We hope, one of these will succeed. :\-) .IP Run 8 .IX Item "Run" (Instance method) Overwrites the Net::Daemon's method by adding a timeout. .PP sub Run ($) { my \f(CW$self\fR = shift; \f(CW$self\fR\->\fBRun()\fR; } .SS "Client part" .IX Subsection "Client part" .IP Child 8 .IX Item "Child" (Class method) Attempts to spawn a server process. The server process is expected to create the file 'ndtest.prt' with the port number. .Sp The method returns a process handle and a port number. The process handle offers a method \fBTerminate\fR that may later be used to stop the server process. .SH "AUTHOR AND COPYRIGHT" .IX Header "AUTHOR AND COPYRIGHT" .Vb 4 \& Net::Daemon is Copyright (C) 1998, Jochen Wiedmann \& Am Eisteich 9 \& 72555 Metzingen \& Germany \& \& Phone: +49 7123 14887 \& Email: joe@ispsoft.de \& \& All rights reserved. .Ve .PP You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file. .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBNet::Daemon\fR\|(3), \fBTest::Harness\fR\|(3)