Start server for test ?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View


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

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

Re: Start server for test ?

Quoted text here. Click to load it

I'm using ExtUtils::ModuleMaker and Test::More (note spelling).

Quoted text here. Click to load it

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.


Re: Start server for test ?

Quoted text here. Click to load it


Site Timeline