Skip to content
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