How can I start a TCP server in the background during a Perl unit test?

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2010-04-16T01:15:15Z Indexed on 2010/04/16 4:13 UTC
Read the original article Hit count: 267

Filed under:
|
|

I am trying to write a unit test for a client server application. To test the client, in my unit test, I want to first start my tcp server (which itself is another perl file). I tried to start the TCP server by forking:

if (! fork()) {
    system ("$^X server.pl") == 0 or die "couldn't start server"
}

So when I call make test after perl Makefile.PL, this test starts and I can see the server starting but after that the unit test just hangs there. So I guess I need to start this server in background and I tried the & at the end to force it to start in background and then test to continue. But, I still couldn't succeed. What am I doing wrong? Thanks.

© Stack Overflow or respective owner

Related posts about perl

Related posts about unit-testing