Skip to content

Commit

Permalink
Info: test 'cyr_info proc' with periodic events
Browse files Browse the repository at this point in the history
  • Loading branch information
elliefm committed Jun 19, 2023
1 parent 6dd34e3 commit 9cb86a8
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
42 changes: 42 additions & 0 deletions cassandane/Cassandane/Cyrus/Info.pm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
package Cassandane::Cyrus::Info;
use strict;
use warnings;
use Cwd qw(realpath);
use Data::Dumper;

use lib '.';
Expand Down Expand Up @@ -264,4 +265,45 @@ sub test_proc_starts
$self->assert_num_equals(0, scalar @output);
}

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

my $sleeper_time = 10; # seconds

# periodic events first fire immediately at startup, and then every
# 'period' minutes thereafter. the fastest we can schedule them is
# every 1 minute, so this test must run for at least several real
# minutes
$self->{instance}->add_event(
name => 'sleeper',
argv => [ realpath('utils/sleeper'), $sleeper_time ],
period => 1,
);
$self->{instance}->start();

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

# observe for three cycles
my $observations = 3;
while ($observations > 0) {
# event should have fired and be running
my @output = $self->run_cyr_info('proc');
$self->assert_num_equals(1, scalar @output);

# wait for it to finish and check again
sleep $sleeper_time;
@output = $self->run_cyr_info('proc');
$self->assert_num_equals(0, scalar @output);

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

# wait until next period
sleep 60 - $sleeper_time;
}
}

1;
31 changes: 31 additions & 0 deletions cassandane/utils/sleeper
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/perl
# like /bin/sleep except ignoring Cyrus-style -C, -M arguments

use warnings;
use strict;

use Sys::Syslog qw(:standard :macros);

sub usage
{
die "usage: $0 [-C imapd.conf] [-M cyrus.conf] seconds\n";
}

my $arg;

while (scalar @ARGV > 1) {
$arg = shift @ARGV;
if ($arg eq '-C' || $arg eq '-M') {
# ignore argument intended for cyrus processes
shift @ARGV;
}
}
usage() if scalar @ARGV != 1;

$arg = shift @ARGV;
usage() if $arg !~ m/^\d+$/;

openlog('sleeper', LOG_LOCAL6) or die "Cannot openlog";
syslog(LOG_INFO, "sleeping for $arg seconds...");
sleep $arg;
syslog(LOG_INFO, "finished");

0 comments on commit 9cb86a8

Please sign in to comment.