1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#!/usr/bin/env perl
# Basic testing of cron functionality.
use strict;
use warnings;
use Test::More;
use FindBin qw($Bin);
use lib "$Bin/lib";
use Carp qw(croak);
use MemcachedTest;
use IO::Socket qw(AF_INET SOCK_STREAM);
use IO::Select;
use Data::Dumper qw/Dumper/;
if (!supports_proxy()) {
plan skip_all => 'proxy not enabled';
exit 0;
}
my $p_srv = new_memcached('-o proxy_config=./t/proxycron.lua -t 1');
my $ps = $p_srv->sock;
$ps->autoflush(1);
sub wait_reload {
my $w = shift;
while (my $line = <$w>) {
if ($line =~ m/type=proxy_conf status=done/) {
last;
}
}
pass("reload complete");
}
# The crons will do some fiddling then issue a self-reload twice.
subtest 'wait for reload' => sub {
my $w = $p_srv->new_sock;
print $w "watch proxyevents\n";
is(<$w>, "OK\r\n", "watcher enabled");
wait_reload($w);
wait_reload($w);
my $stats = mem_stats($ps);
cmp_ok($stats->{proxy_config_cron_runs}, '>', 3, "crons ran");
is($stats->{proxy_config_cron_fails}, 0, "no crons failed");
};
done_testing();
|