develooper Front page | perl.qa | Postings from April 2015

Communicating between processes in test suite run

Thread Next
From:
Cosimo Streppone
Date:
April 23, 2015 15:59
Subject:
Communicating between processes in test suite run
Message ID:
553916E6.4080800@opera.com
Hi,

trying to pick your brains here.
I hope to be able to explain decently what I'm trying to achieve.

This is about the test suite of Net::Statsd::Server, a perl port
of the javascript statsd daemon, and in particular the
t/integration-tests/*.t cases.

Integration here means that the *.t files, through a
Test::Statsd class, bring up a Net::Statsd::Server server
on a fixed port, f.ex. 40001.

This "bringing up" happens by fork and exec of a given binary
(bin/statsd in the same dist). I chose this path because I can
run my unmodified test suite against the javascript statsd
and test that the js and perl versions behave exactly the same.

Now, problem.

I'd like to use port 0 to bring up the daemon, so that the test suite
can be run in parallel without port clashes. With port == 0 the TCP/UDP
bind will happen on a random free port.

When the fork + exec'd daemon chooses a random port, I need to be able
to know which port it has bound itself to, and here lies the problem.

How would you communicate this information back to the parent process
that spawns the daemon binary?

The solution I found so far works but it's totally unsatisfactory to me.

Basically I set an ENV variable such as $ENV{STATSD_PORT_FILE} with a
temporary random file name.

In the daemon startup code, if $ENV{HARNESS_ACTIVE} and
$ENV{STATSD_PORT_FILE} are both there (since the daemon is spawned by
the *.t script), then the port number is saved into the file name
indicated by $ENV{STATSD_PORT_FILE}.

I don't like this mess.

-- 
Cosimo

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About