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

Re: Communicating between processes in test suite run

Thread Previous | Thread Next
From:
Tim Bunce
Date:
April 23, 2015 17:02
Subject:
Re: Communicating between processes in test suite run
Message ID:
20150423170237.GA1772@timac-2.local
On Thu, Apr 23, 2015 at 05:59:34PM +0200, Cosimo Streppone wrote:
> 
> 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?

Perhaps dodge the problem by not picking a random port. Have the parent
process look for free ports itself in some obscure part of the range.
Then pass that port number to the daemon. There's a very small race
hazard here but that seems quite acceptable under the circumstances.
Especially as you'll know you've hit it because the statsd daemon will die.

> 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.

How is "the port number is saved into the file" when you don't know
which port it has bound itself to?

Tim.

Thread Previous | 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