File: proxydepthlim.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 (46 lines) | stat: -rw-r--r-- 1,058 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
#!/usr/bin/env perl

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 $t = Memcached::ProxyTest->new(servers => [12161]);

my $p_srv = new_memcached('-o proxy_config=./t/proxydepthlim.lua -t 1');
my $ps = $p_srv->sock;
$ps->autoflush(1);

$t->set_c($ps);
#$t->accept_backends();

subtest 'over-depth' => sub {
    my $holder = $p_srv->new_sock;
    # enqueue some requests.
    my $cmd = "mg foo s t v\r\n";
    my $todo = '';
    for (1..4) {
        $todo .= $cmd;
    }
    print $holder $todo;
    sleep 0.25; # ensure holder client is seen first
    # We never look at the backend in this test.
    $t->c_send($cmd);
    $t->c_recv("SERVER_ERROR backend failure\r\n", 'depth limit reached');

    my $s = mem_stats($ps);
    is($s->{proxy_request_failed_depth}, 1, "got a fast failure");
};

done_testing();