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