diff --git a/cassandane/Cassandane/Cyrus/Info.pm b/cassandane/Cassandane/Cyrus/Info.pm index f826740120..e07228b86e 100644 --- a/cassandane/Cassandane/Cyrus/Info.pm +++ b/cassandane/Cassandane/Cyrus/Info.pm @@ -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;