File: proxycron.t

package info (click to toggle)
memcached 1.6.39-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,320 kB
  • sloc: ansic: 62,281; perl: 12,500; sh: 4,569; makefile: 468; python: 402; xml: 59
file content (47 lines) | stat: -rw-r--r-- 1,088 bytes parent folder | download | duplicates (2)
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();