Mercurial > hg > nginx-tests
annotate h2_trailers.t @ 1752:ba6e24e38f03
Tests: improved stop_daemons() to send signal again.
As was observed, it's possible that a signal to complete a uwsgi daemon
can be ignored while it is starting up, which results in tests hang due
to eternal waiting on child processes termination. Notably, it is seen
when running tests with a high number of prove jobs on a low-profile VM
against nginx with broken modules and/or configuration. To reproduce:
$ TEST_NGINX_GLOBALS=ERROR prove -j16 uwsgi*.t
Inspecting uwsgi under ktrace on FreeBSD confirms that a SIGTERM signal
is ignored at the very beginning of uwsgi startup. It is then replaced
with a default action after listen(), thus waiting until uwsgi is ready
to accept new TCP connections doesn't completely solve the hang window.
The fix is to retry sending a signal some time after waitpid(WNOHANG)
continuously demonstrated no progress with reaping a signaled process.
It is modelled after f13ead27f89c that improved stop() for nginx.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 29 Dec 2021 22:29:23 +0300 |
parents | 5b1fa6e32549 |
children | 236d038dc04a |
rev | line source |
---|---|
1193 | 1 #!/usr/bin/perl |
2 | |
3 # (C) Sergey Kandaurov | |
4 # (C) Nginx, Inc. | |
5 | |
6 # Tests for HTTP/2 trailers. | |
7 | |
8 ############################################################################### | |
9 | |
10 use warnings; | |
11 use strict; | |
12 | |
13 use Test::More; | |
14 | |
15 BEGIN { use FindBin; chdir($FindBin::Bin); } | |
16 | |
17 use lib 'lib'; | |
18 use Test::Nginx; | |
19 use Test::Nginx::HTTP2; | |
20 | |
21 ############################################################################### | |
22 | |
23 select STDERR; $| = 1; | |
24 select STDOUT; $| = 1; | |
25 | |
1381
97c8280de681
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1194
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/http http_v2/)->plan(22) |
1193 | 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 http2; | |
41 server_name localhost; | |
42 | |
43 location / { | |
44 add_trailer X-Var $host; | |
45 } | |
46 | |
47 location /continuation { | |
48 # many trailers to send in parts | |
49 add_trailer X-LongHeader $arg_h; | |
50 add_trailer X-LongHeader $arg_h; | |
51 add_trailer X-LongHeader $arg_h; | |
52 add_trailer X-LongHeader $arg_h; | |
53 add_trailer X-LongHeader $arg_h; | |
54 } | |
55 } | |
56 } | |
57 | |
58 EOF | |
59 | |
60 $t->write_file('index.html', 'SEE-THIS'); | |
61 $t->write_file('empty', ''); | |
62 $t->write_file('continuation', 'SEE-THIS'); | |
1381
97c8280de681
Tests: removed TODO and try_run() checks for legacy versions.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1194
diff
changeset
|
63 $t->run(); |
1193 | 64 |
65 ############################################################################### | |
66 | |
67 my ($s, $sid, $frames, $frame); | |
68 | |
69 $s = Test::Nginx::HTTP2->new(); | |
70 $sid = $s->new_stream({ path => '/' }); | |
71 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | |
72 @$frames = grep { $_->{type} =~ "HEADERS|DATA" } @$frames; | |
73 | |
74 is(@$frames, 3, 'frames'); | |
75 | |
76 $frame = shift @$frames; | |
77 is($frame->{headers}->{':status'}, 200, 'header'); | |
78 is($frame->{headers}->{'x-var'}, undef, 'header not trailer'); | |
79 is($frame->{flags}, 4, 'header flags'); | |
80 | |
81 $frame = shift @$frames; | |
82 is($frame->{data}, 'SEE-THIS', 'data'); | |
83 is($frame->{flags}, 0, 'data flags'); | |
84 | |
85 $frame = shift @$frames; | |
86 is($frame->{headers}->{'x-var'}, 'localhost', 'trailer'); | |
87 is($frame->{flags}, 5, 'trailer flags'); | |
88 | |
89 # with zero content-length | |
90 | |
91 $s = Test::Nginx::HTTP2->new(); | |
92 $sid = $s->new_stream({ path => '/empty' }); | |
93 $frames = $s->read(all => [{ sid => $sid, fin => 1 }]); | |
94 @$frames = grep { $_->{type} =~ "HEADERS|DATA" } @$frames; | |
95 | |
96 is(@$frames, 2, 'no data - frames'); | |
97 | |
98 $frame = shift @$frames; | |
99 is($frame->{headers}->{':status'}, 200, 'no data - header'); | |
100 is($frame->{flags}, 4, 'no data - header flags'); | |
101 | |
102 $frame = shift @$frames; | |
103 is($frame->{headers}->{'x-var'}, 'localhost', 'no data - trailer'); | |
104 is($frame->{flags}, 5, 'no data - trailer flags'); | |
105 | |
106 # CONTINUATION in response trailers | |
107 | |
108 $s = Test::Nginx::HTTP2->new(); | |
1646
5b1fa6e32549
Tests: avoid http2_max_field_size in h2_trailers.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1381
diff
changeset
|
109 $sid = $s->new_stream({ path => '/continuation?h=' . 'x' x 4000 }); |
1194
39cfdf581253
Tests: fixed CONTINUATION test in h2_trailers.t.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1193
diff
changeset
|
110 $frames = $s->read(all => [{ sid => $sid, type => 'CONTINUATION' }]); |
1193 | 111 @$frames = grep { $_->{type} =~ "HEADERS|CONTINUATION|DATA" } @$frames; |
112 | |
113 is(@$frames, 4, 'continuation - frames'); | |
114 | |
115 $frame = shift @$frames; | |
116 is($frame->{headers}->{':status'}, 200, 'continuation - header'); | |
117 is($frame->{flags}, 4, 'continuation - header flags'); | |
118 | |
119 $frame = shift @$frames; | |
120 is($frame->{data}, 'SEE-THIS', 'continuation - data'); | |
121 is($frame->{flags}, 0, 'continuation - data flags'); | |
122 | |
123 $frame = shift @$frames; | |
124 is($frame->{type}, 'HEADERS', 'continuation - trailer'); | |
125 is($frame->{flags}, 1, 'continuation - trailer flags'); | |
126 | |
127 $frame = shift @$frames; | |
128 is($frame->{type}, 'CONTINUATION', 'continuation - trailer continuation'); | |
129 is($frame->{flags}, 4, 'continuation - trailer continuation flags'); | |
130 | |
131 ############################################################################### |