Mercurial > hg > nginx-tests
annotate stream_js_var.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 | 9d4c88e5c183 |
children |
rev | line source |
---|---|
1666
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
2 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
3 # (C) Dmitry Volyntsev |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
5 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
6 # Tests for stream njs module, js_var directive. |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
7 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
9 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
11 use strict; |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
12 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
14 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
15 BEGIN { use FindBin; chdir($FindBin::Bin); } |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
16 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
17 use lib 'lib'; |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
18 use Test::Nginx; |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
19 use Test::Nginx::Stream qw/ stream /; |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
20 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
21 ############################################################################### |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
22 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
23 select STDERR; $| = 1; |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
24 select STDOUT; $| = 1; |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
25 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
26 my $t = Test::Nginx->new()->has(qw/stream stream_return/) |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
27 ->write_file_expand('nginx.conf', <<'EOF'); |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
28 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
29 %%TEST_GLOBALS%% |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
30 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
31 daemon off; |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
32 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
33 events { |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
34 } |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
35 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
36 stream { |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
37 %%TEST_GLOBALS_STREAM%% |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
38 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
39 js_import test.js; |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
40 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
41 js_var $foo; |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
42 js_var $bar a:$remote_addr; |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
43 js_set $var test.varr; |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
44 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
45 server { |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
46 listen 127.0.0.1:8081; |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
47 return $bar$foo; |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
48 } |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
49 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
50 server { |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
51 listen 127.0.0.1:8082; |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
52 return $var$foo; |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
53 } |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
54 } |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
55 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
56 EOF |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
57 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
58 $t->write_file('test.js', <<EOF); |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
59 function varr(s) { |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
60 s.variables.foo = 'xxx'; |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
61 return ''; |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
62 } |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
63 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
64 export default {varr}; |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
65 EOF |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
66 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
67 $t->try_run('no stream js_var')->plan(2); |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
68 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
69 ############################################################################### |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
70 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
71 is(stream('127.0.0.1:' . port(8081))->io('###'), 'a:127.0.0.1', |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
72 'default value'); |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
73 is(stream('127.0.0.1:' . port(8082))->io('###'), 'xxx', 'value set'); |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
74 |
9d4c88e5c183
Tests: added js_var directive tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff
changeset
|
75 ############################################################################### |