Permalink
Browse files

Merge pull request #7 from ReturnPath/master

Bind to random port
  • Loading branch information...
2 parents 7f26f76 + 236e394 commit c5381214a9024bd7137d8d9cde03f41519810adc @cosimo committed Aug 10, 2012
Showing with 4 additions and 10 deletions.
  1. +3 −4 t/MockServer.pm
  2. +1 −6 t/mock-server.t
View
7 t/MockServer.pm
@@ -3,20 +3,19 @@ use strict;
use IO::Socket::INET;
use IO::Select;
-use constant PORT => 8125;
-
$| = 1;
use vars qw ($socket @messages $select);
sub start {
$socket = new IO::Socket::INET(
- LocalPort => PORT,
+ LocalAddr => '127.0.0.1',
Proto => 'udp',
) or die "unable to create socket: $!\n";
$select = IO::Select->new($socket);
reset_messages();
+ return $socket->sockport();
}
my $_data = "";
@@ -94,7 +93,7 @@ sub reset_messages { @messages = () }
sub stop {
my $s_send = IO::Socket::INET->new(
- PeerAddr => '127.0.0.1:'. PORT,
+ PeerAddr => '127.0.0.1:'. $socket->sockport(),
Proto => 'udp',
) or die "failed to create client socket: $!\n";
$s_send->send("quit");
View
7 t/mock-server.t
@@ -32,19 +32,14 @@ BEGIN {
use lib $dirname;
use MockServer;
-BEGIN {
- $Net::Statsd::HOST = 'localhost';
- $Net::Statsd::PORT = MockServer::PORT();
-}
-
note <<"DESCRIPTION";
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
These test verify basic operation of the statsd client
by validating the udp messages sent to a mock server
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
DESCRIPTION
-MockServer::start();
+$Net::Statsd::PORT = MockServer::start();
my $msgs;
Net::Statsd::timing('test.timer', 345);

0 comments on commit c538121

Please sign in to comment.