Skip to content

Commit

Permalink
Info: test 'cyr_info proc' with daemons
Browse files Browse the repository at this point in the history
  • Loading branch information
elliefm committed Jun 23, 2023
1 parent a43506a commit 9f99dfd
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions cassandane/Cassandane/Cyrus/Info.pm
Original file line number Diff line number Diff line change
Expand Up @@ -347,4 +347,48 @@ sub test_proc_scheduled_events
$self->assert_num_equals(0, scalar @output);
}

sub test_proc_daemons
:NoStartInstances
{
my ($self) = @_;

my $sleeper_time = 10; # seconds
my $daemons = 3;

for my $i (1 .. $daemons) {
# you wouldn't usually run a daemon that exits and needs to be
# restarted every ten seconds, but it's useful for testing
# that cyr_info proc notices the pid changing
$self->{instance}->add_daemon(
name => "sleeper$i",
argv => [ realpath('utils/sleeper'), $sleeper_time ],
);
}
$self->{instance}->start();

sleep 2; # offset our checks a little to avoid races

my $observations = 3;
my %lastpid = map {; "sleeper$_" => 0 } (1 .. $daemons);
while ($observations > 0) {
my @output = $self->run_cyr_info('proc');

# always exactly one process per daemon
$self->assert_num_equals($daemons, scalar @output);

# expect a new pid each time
my ($pid, $servicename, $host, $user, $mailbox, $cmd)
= split /\s/, $output[0], 6;
$self->assert_num_not_equals($lastpid{$servicename}, $pid);
$lastpid{$servicename} = $pid;

# skip final wait if we're done
$observations--;
last if $observations == 0;

# wait for next restart
sleep $sleeper_time;
}
}

1;

0 comments on commit 9f99dfd

Please sign in to comment.