Mercurial > hg > nginx-tests
annotate js_variables.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 | 18ac4d9e5a2a |
children |
rev | line source |
---|---|
1442
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
2 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
3 # (C) Dmitry Volyntsev |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
5 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
6 # Tests for http njs module, setting nginx variables. |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
7 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
9 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
11 use strict; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
12 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
14 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
16 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
19 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
20 ############################################################################### |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
21 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
22 select STDERR; $| = 1; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
23 select STDOUT; $| = 1; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
24 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
25 my $t = Test::Nginx->new()->has(qw/http rewrite/) |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
26 ->write_file_expand('nginx.conf', <<'EOF'); |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
27 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
28 %%TEST_GLOBALS%% |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
29 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
30 daemon off; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
31 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
32 events { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
33 } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
34 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
35 http { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
36 %%TEST_GLOBALS_HTTP%% |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
37 |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
38 js_set $test_var test.variable; |
1442
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
39 |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
40 js_import test.js; |
1442
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
41 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
42 server { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
43 listen 127.0.0.1:8080; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
44 server_name localhost; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
45 |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
46 set $foo test.foo_orig; |
1442
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
47 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
48 location /var_set { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
49 return 200 $test_var$foo; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
50 } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
51 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
52 location /content_set { |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
53 js_content test.content_set; |
1442
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
54 } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
55 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
56 location /not_found_set { |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
57 js_content test.not_found_set; |
1442
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
58 } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
59 } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
60 } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
61 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
62 EOF |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
63 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
64 $t->write_file('test.js', <<EOF); |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
65 function variable(r) { |
1442
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
66 r.variables.foo = r.variables.arg_a; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
67 return 'test_var'; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
68 } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
69 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
70 function content_set(r) { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
71 r.variables.foo = r.variables.arg_a; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
72 r.return(200, r.variables.foo); |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
73 } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
74 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
75 function not_found_set(r) { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
76 try { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
77 r.variables.unknown = 1; |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
78 } catch (e) { |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
79 r.return(500, e); |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
80 } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
81 } |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
82 |
1751
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
83 export default {variable, content_set, not_found_set}; |
18ac4d9e5a2a
Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1614
diff
changeset
|
84 |
1442
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
85 EOF |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
86 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
87 $t->try_run('no njs')->plan(3); |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
88 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
89 ############################################################################### |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
90 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
91 like(http_get('/var_set?a=bar'), qr/test_varbar/, 'var set'); |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
92 like(http_get('/content_set?a=bar'), qr/bar/, 'content set'); |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
93 like(http_get('/not_found_set'), qr/variable not found/, 'not found exception'); |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
94 |
4281225b0c52
Tests: njs tests for setting nginx variables.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
95 ############################################################################### |