Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite Error message Address in use #485 #487

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/Statocles/Command.pm
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,15 @@ sub main {
}

# Using start() instead of run() so we can stop() inside the tests
$daemon->start;
# and eval to do a partial rewrite of some error messages
eval {$daemon->start};
if ($@ ) {
if ( $@ =~ /^Can't create listen socket:/) {
my $port = join ' or ',@{$daemon->listen()};
$@ =~ s/:/ for ($port):/;
}
die $@
}

# Find the port we're listening on
my $id = $daemon->acceptors->[0];
Expand Down
24 changes: 24 additions & 0 deletions t/command/daemon.t
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,30 @@ 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 {
capture { Statocles::Command->main( @args ) };
}
my $err = $@;
my $port = $1 if $@ =~ qr{http://\*:(\d*)};
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