Net::Daemon::Test(3pm) | User Contributed Perl Documentation | Net::Daemon::Test(3pm) |
Net::Daemon::Test - support functions for testing Net::Daemon servers
# 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(\%attr, \@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't forget to use # the timeout option. use Net::Daemon::Test (); my($handle, $port) = eval { Net::Daemon::Test->Child(5, # Number of subtests 'servertask', '--timeout', '20') }; if ($@) { print "not ok 1 $@\n"; exit 0; } print "ok 1\n"; # Real tests following here ... # Terminate the server $handle->Terminate();
This module is a frame for creating test scripts of Net::Daemon based server packages, preferrably using Test::Harness, but that's your choice.
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 fork(), but that's the best possibility to make the test scripts portable to Windows without requiring threads in the test script.)
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 Bind method attempts to allocate a port automatically. Once a port is allocated, the number is stored in the file "ndtest.prt".
After spawning the server process, the child will wait ten seconds (hopefully sufficient) for the creation of ndtest.prt.
sub Run ($) {
my $self = shift;
$self->Run(); }
The method returns a process handle and a port number. The process handle offers a method Terminate that may later be used to stop the server process.
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.
You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.
2022-10-13 | perl v5.34.0 |