File: proxyrctxtimeout.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 (130 lines) | stat: -rw-r--r-- 3,528 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/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;
}

# Set up the listeners _before_ starting the proxy.
# the fourth listener is only occasionally used.
my $t = Memcached::ProxyTest->new(servers => [12141, 12142, 12143]);

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

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

subtest 'sleep' => sub {
    for my $try ('before', 'after', 'both', 'twice', 'enqueue', 'subwait', 'subdoublewait') {
        $t->c_send("mg sleep/$try t\r\n");
        $t->be_recv_c(0, "near got request");
        $t->be_send(0, "HD t94\r\n");
        $t->c_recv_be($try);
    }
    $t->clear();
};

subtest 'no timeout' => sub {
    # first response is good
    $t->c_send("mg cond_timeout/foo\r\n");
    $t->be_recv_c(0);
    $t->be_send(0, "HD\r\n");
    $t->c_recv_be();
    $t->clear();
};

subtest 'first req times out' => sub {
    $t->c_send("mg cond_timeout/boo t\r\n");
    $t->be_recv_c([1,2], "far backends received requests");
    $t->be_recv_c(0, "near req still arrived");
    $t->be_send([1,2], "HD t90\r\n");
    $t->c_recv_be();
    # Should get eaten.
    $t->be_send(0, "HD t40\r\n");
    $t->clear();
};

subtest 'first req times out, but still returns' => sub {
    $t->c_send("mg cond_timeout/qoo t\r\n");
    $t->be_recv_c([1,2], "near timeout, far received req");
    $t->be_recv_c(0, "near received request");

    $t->be_send(0, "HD t14\r\n");
    $t->c_recv_be("near timed out but client got its response");
    # returned but doesn't go anywhere.
    $t->be_send([1,2], "HD t17\r\n");
    $t->clear();
};

subtest 'enqueue_timeout' => sub {
    $t->c_send("mg enqueue_timeout/foo t\r\n");
    $t->be_recv_c([1,2], "near timeout, far received req");
    $t->be_recv_c(0, "near req still arrived");
    $t->be_send([1,2], "HD t91\r\n");
    $t->c_recv_be();
    $t->be_send(0, "HD t15\r\n");
    $t->clear();
};

subtest 'enqueue_and_wait no timeout' => sub {
    $t->c_send("mg enqueue_timeout/foo t\r\n");
    $t->be_recv_c(0, "near req arrived");
    $t->be_send(0, "HD t16\r\n");
    $t->c_recv_be();
    $t->clear();
};

subtest 'handle_timeout' => sub {
    $t->c_send("mg handle_timeout/foo t\r\n");
    $t->be_recv_c([1,2], "near timeout, far received req");
    $t->be_recv_c(0, "near req still arrived");
    $t->be_send([1,2], "HD t92\r\n");
    $t->c_recv_be();
    $t->be_send(0, "HD t16\r\n");
    $t->clear();
};

subtest 'wait on the same handle twice' => sub {
    $t->c_send("mg wait_more/foo t\r\n");
    $t->be_recv_c(0, "near got request");
    # Let it internally time out.
    sleep 0.75;
    pass("short sleep");
    $t->be_send(0, "HD t93\r\n");
    $t->c_recv_be();
    $t->clear();
};

subtest 'wait handle no timeout' => sub {
    $t->c_send("mg wait_more/foo t\r\n");
    $t->be_recv_c(0, "near got request");
    $t->be_send(0, "HD t93\r\n");
    $t->c_recv("SERVER_ERROR no timeout\r\n", "client received SERVER_ERROR");
    $t->clear();
};

subtest 'wait double' => sub {
    $t->c_send("mg wait_double/foo t\r\n");
    $t->be_recv_c(0, "near got request");
    # Let it internally time out.
    sleep 0.75;
    pass("short sleep");
    $t->be_send(0, "HD t98\r\n");
    $t->c_recv_be();
    $t->clear();
};

done_testing();