Mercurial > hg > nginx-tests
annotate mirror.t @ 1240:f7eb2875ed45
Tests: avoid interleaved output in Upgrade handling tests.
When the testing script is run in verbose mode by prove that redirects stdout,
a garbled verbose mode line from backend can be produced that incorporates TAP
output of an individual test result, which eventually breaks the testing plan.
Notably, this happens when testing sending multiple frames if backend started
to respond before all frames were received. This is possible due to the line
boundary used as an indicator of last bytes to receive before starting to send.
The fix is to amend the only last frame of many specially, for that purpose.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 15 Nov 2017 20:16:09 +0300 |
parents | a6453cf5786a |
children | 97c8280de681 |
rev | line source |
---|---|
1208
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
6 # Tests for http mirror module. |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
16 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http mirror/); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 $t->write_file_expand('nginx.conf', <<'EOF'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 events { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 http { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_HTTP%% |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 log_format test $uri; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 server { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 listen 127.0.0.1:8080; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 server_name localhost; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 location / { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 mirror /mirror; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 location /off { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 mirror off; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 location /many { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 mirror /mirror/1; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
55 mirror /mirror/2; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
56 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 location /mirror { |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 log_subrequest on; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 access_log test$args.log test; |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 } |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 EOF |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 $t->write_file('index.html', ''); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 $t->write_file('many', ''); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 $t->write_file('off', ''); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 $t->try_run('no mirror')->plan(8); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
72 ############################################################################### |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
73 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
74 like(http_get('/index.html?1'), qr/200 OK/, 'request'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
75 like(http_get('/?2'), qr/200 OK/, 'internal redirect'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
76 like(http_get('/off?3'), qr/200 OK/, 'mirror off'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
77 like(http_get('/many?4'), qr/200 OK/, 'mirror many'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
78 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
79 $t->stop(); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
80 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
81 is($t->read_file('test1.log'), "/mirror\n", 'log - request'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
82 is($t->read_file('test2.log'), "/mirror\n/mirror\n", 'log - redirect'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
83 ok(!-e $t->testdir() . '/test3.log', 'log - mirror off'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
84 is($t->read_file('test4.log'), "/mirror/1\n/mirror/2\n", 'log - mirror many'); |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
85 |
a6453cf5786a
Tests: http mirror module tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
86 ############################################################################### |