comparison memcached_fake_extra.t @ 1581:463d6863d360

Tests: tests for extra data and short responses.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 06 Jul 2020 18:37:20 +0300
parents
children 5ac6efbe5552
comparison
equal deleted inserted replaced
1580:9e142c0e34b2 1581:463d6863d360
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4 # (C) Nginx, Inc.
5
6 # Test for memcached backend returning extra data after trailer.
7
8 ###############################################################################
9
10 use warnings;
11 use strict;
12
13 use Test::More;
14 use Socket qw/ CRLF /;
15
16 BEGIN { use FindBin; chdir($FindBin::Bin); }
17
18 use lib 'lib';
19 use Test::Nginx;
20
21 ###############################################################################
22
23 select STDERR; $| = 1;
24 select STDOUT; $| = 1;
25
26 my $t = Test::Nginx->new()->has(qw/http rewrite memcached/)->plan(1)
27 ->write_file_expand('nginx.conf', <<'EOF');
28
29 %%TEST_GLOBALS%%
30
31 daemon off;
32
33 events {
34 }
35
36 http {
37 %%TEST_GLOBALS_HTTP%%
38
39 server {
40 listen 127.0.0.1:8080;
41 server_name localhost;
42
43 location / {
44 set $memcached_key $uri;
45 memcached_pass 127.0.0.1:8081;
46 }
47 }
48 }
49
50 EOF
51
52 $t->run_daemon(\&memcached_fake_daemon);
53 $t->run();
54
55 $t->waitforsocket('127.0.0.1:' . port(8081))
56 or die "Can't start fake memcached";
57
58 ###############################################################################
59
60 $t->todo_alerts() unless $t->has_version('1.19.1');
61
62 like(http_get('/'), qr/SEE-THIS/, 'memcached data after trailer');
63
64 ###############################################################################
65
66 sub memcached_fake_daemon {
67 my $server = IO::Socket::INET->new(
68 Proto => 'tcp',
69 LocalAddr => '127.0.0.1:' . port(8081),
70 Listen => 5,
71 Reuse => 1
72 )
73 or die "Can't create listening socket: $!\n";
74
75 local $SIG{PIPE} = 'IGNORE';
76
77 while (my $client = $server->accept()) {
78 $client->autoflush(1);
79
80 while (<$client>) {
81 last if (/\x0d\x0a$/);
82 }
83
84 print $client 'VALUE / 0 8' . CRLF;
85 print $client 'SEE-THIS' . CRLF . 'END' . CRLF
86 . "\0" . ("1" x 1024);
87
88 select(undef, undef, undef, 0.2);
89
90 print $client 'EXTRA' . CRLF;
91 close $client;
92 }
93 }
94
95 ###############################################################################