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