Skip to content

Commit

Permalink
Rewrite Error message Address in use #485
Browse files Browse the repository at this point in the history
"Can't create listen socket: Address already in use" is rewriten as
"Can't create listen socket for (http://*:3000): Address already in use"
it changes all "Can't create listen socket:" messages to
"Can't create listen socket for ($listen_URL):"

It has a test in t/command/daemon.t that test the new messge when no port
is specified


Signed-off-by: Jose Luis Perez Diez <[email protected]>
  • Loading branch information
jluis committed Apr 11, 2016
1 parent cadad73 commit 075185e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/Statocles/Command.pm
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,12 @@ sub main {
}

# Using start() instead of run() so we can stop() inside the tests
$daemon->start;
eval {$daemon->start};
if ($@) {
my $port = $opt{port} ||$ENV{MOJO_LISTEN} || 3000;
$@ =~ s/socket:/socket on port $port:/;
die $@;
}

# Find the port we're listening on
my $id = $daemon->acceptors->[0];
Expand Down
25 changes: 25 additions & 0 deletions t/command/daemon.t
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,31 @@ subtest 'listen on a specific port' => sub {
'contains http port information';
};

subtest 'Try to launch 2 daemons' => sub {

local $ENV{MOJO_LOG_LEVEL} = 'info'; # But sometimes this isn't set?
my @args = (
'--config' => "$config_fn",
'daemon',
'-v', # watch lines are now behind -v
);
if (my $pid = fork) {
sleep 1;
eval { Statocles::Command->main( @args ) };
kill 9, $pid;
} else {
#my ( $out2, $err2, $exit2 ) =
capture { Statocles::Command->main( @args ) };
}
my $err = $@ =~ m|\(http://\*:(\d*)\):|;
my $port = $1;
is $port, 3000, 'correct port';
ok $err, "there was anoter proccess listening at $port";
like $@, qr{^Can't create listen socket for \(http://\*:$port\):},
'contains http port information';
};


subtest '--date' => sub {
my ( $tmp, $config_fn, $config ) = build_temp_site( $SHARE_DIR );

Expand Down

0 comments on commit 075185e

Please sign in to comment.