Start server for test ?

K

Kaare Rasmussen

Hi

I've written some tests for my shining new server - so 'Build test' has
something to do.

Yes, I use Module::Build and Test::more.

Problem is, how do I start the server as a daemon and kill it when the
client tests are run?

In production I'd just run it with

perl -MBusiness::Bof::Server::CLI -e run -- -c t/bof.xml &

and kill it when it hs lived long enough. But this doesn't work in a Build
test.

Any ideas to daemonize the server with the test in Module::Build (and store
the pid somewhere so I can kill it again)?
 
A

Anno Siegel

Kaare Rasmussen said:
Hi

I've written some tests for my shining new server - so 'Build test' has
something to do.

Yes, I use Module::Build and Test::more.

I'm using ExtUtils::ModuleMaker and Test::More (note spelling).
Problem is, how do I start the server as a daemon and kill it when the
client tests are run?

In production I'd just run it with

perl -MBusiness::Bof::Server::CLI -e run -- -c t/bof.xml &

and kill it when it hs lived long enough. But this doesn't work in a Build
test.

Any ideas to daemonize the server with the test in Module::Build (and store
the pid somewhere so I can kill it again)?

I don't see what the question has to do with Module::Build and Test::More.

If you need to run a process in the background, the most basic method
is to fork and exec it:

my $cmd = 'echo starting; sleep 10; echo done';
defined( my $pid = fork) or die "fork: $!";
exec $cmd unless $pid; # the kid does this
# parent again (kid doesn't reach this)
sleep 3;
kill 'INT', $pid;

If you run this, you'll note that the background process is killed
before it can print "done". Change "sleep 10" to "sleep 2" in $cmd
and it runs to completion.

Now set $cmd = 'perl -MBusiness::Bof::Server::CLI -e run -- -c t/bof.xml'
and you got what you want.

See "perldoc -f fork" and "perldoc -f exec" for details and
"perldoc perlipc" for variants and alternatives.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top