Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #7 from ReturnPath/master

Bind to random port
  • Loading branch information...
commit c5381214a9024bd7137d8d9cde03f41519810adc 2 parents 7f26f76 + 236e394
Cosimo Streppone authored

Showing 2 changed files with 4 additions and 10 deletions. Show diff stats Hide diff stats

  1. +3 4 t/MockServer.pm
  2. +1 6 t/mock-server.t
7 t/MockServer.pm
@@ -3,20 +3,19 @@ use strict;
3 3 use IO::Socket::INET;
4 4 use IO::Select;
5 5
6   -use constant PORT => 8125;
7   -
8 6 $| = 1;
9 7
10 8 use vars qw ($socket @messages $select);
11 9
12 10 sub start {
13 11 $socket = new IO::Socket::INET(
14   - LocalPort => PORT,
  12 + LocalAddr => '127.0.0.1',
15 13 Proto => 'udp',
16 14 ) or die "unable to create socket: $!\n";
17 15
18 16 $select = IO::Select->new($socket);
19 17 reset_messages();
  18 + return $socket->sockport();
20 19 }
21 20
22 21 my $_data = "";
@@ -94,7 +93,7 @@ sub reset_messages { @messages = () }
94 93
95 94 sub stop {
96 95 my $s_send = IO::Socket::INET->new(
97   - PeerAddr => '127.0.0.1:'. PORT,
  96 + PeerAddr => '127.0.0.1:'. $socket->sockport(),
98 97 Proto => 'udp',
99 98 ) or die "failed to create client socket: $!\n";
100 99 $s_send->send("quit");
7 t/mock-server.t
@@ -32,11 +32,6 @@ BEGIN {
32 32 use lib $dirname;
33 33 use MockServer;
34 34
35   -BEGIN {
36   - $Net::Statsd::HOST = 'localhost';
37   - $Net::Statsd::PORT = MockServer::PORT();
38   -}
39   -
40 35 note <<"DESCRIPTION";
41 36 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
42 37 These test verify basic operation of the statsd client
@@ -44,7 +39,7 @@ by validating the udp messages sent to a mock server
44 39 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
45 40 DESCRIPTION
46 41
47   -MockServer::start();
  42 +$Net::Statsd::PORT = MockServer::start();
48 43 my $msgs;
49 44
50 45 Net::Statsd::timing('test.timer', 345);

0 comments on commit c538121

Please sign in to comment.
Something went wrong with that request. Please try again.