Skip to content

Commit

Permalink
Merge pull request #7 from ReturnPath/master
Browse files Browse the repository at this point in the history
Bind to random port
  • Loading branch information
cosimo committed Aug 10, 2012
2 parents 7f26f76 + 236e394 commit c538121
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
7 changes: 3 additions & 4 deletions t/MockServer.pm
Expand Up @@ -3,20 +3,19 @@ use strict;
use IO::Socket::INET; use IO::Socket::INET;
use IO::Select; use IO::Select;


use constant PORT => 8125;

$| = 1; $| = 1;


use vars qw ($socket @messages $select); use vars qw ($socket @messages $select);


sub start { sub start {
$socket = new IO::Socket::INET( $socket = new IO::Socket::INET(
LocalPort => PORT, LocalAddr => '127.0.0.1',
Proto => 'udp', Proto => 'udp',
) or die "unable to create socket: $!\n"; ) or die "unable to create socket: $!\n";


$select = IO::Select->new($socket); $select = IO::Select->new($socket);
reset_messages(); reset_messages();
return $socket->sockport();
} }


my $_data = ""; my $_data = "";
Expand Down Expand Up @@ -94,7 +93,7 @@ sub reset_messages { @messages = () }


sub stop { sub stop {
my $s_send = IO::Socket::INET->new( my $s_send = IO::Socket::INET->new(
PeerAddr => '127.0.0.1:'. PORT, PeerAddr => '127.0.0.1:'. $socket->sockport(),
Proto => 'udp', Proto => 'udp',
) or die "failed to create client socket: $!\n"; ) or die "failed to create client socket: $!\n";
$s_send->send("quit"); $s_send->send("quit");
Expand Down
7 changes: 1 addition & 6 deletions t/mock-server.t
Expand Up @@ -32,19 +32,14 @@ BEGIN {
use lib $dirname; use lib $dirname;
use MockServer; use MockServer;


BEGIN {
$Net::Statsd::HOST = 'localhost';
$Net::Statsd::PORT = MockServer::PORT();
}

note <<"DESCRIPTION"; note <<"DESCRIPTION";
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
These test verify basic operation of the statsd client These test verify basic operation of the statsd client
by validating the udp messages sent to a mock server by validating the udp messages sent to a mock server
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
DESCRIPTION DESCRIPTION


MockServer::start(); $Net::Statsd::PORT = MockServer::start();
my $msgs; my $msgs;


Net::Statsd::timing('test.timer', 345); Net::Statsd::timing('test.timer', 345);
Expand Down

0 comments on commit c538121

Please sign in to comment.