annotate js_dump.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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1534
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
2
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
3 # (C) Dmitry Volyntsev
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
4 # (C) Nginx, Inc.
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
5
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
6 # Tests for http njs module, request object dump.
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
7
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
8 ###############################################################################
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
9
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
10 use warnings;
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
11 use strict;
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
12
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
13 use Test::More;
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
14 use Socket qw/ CRLF /;
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
15
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
16 BEGIN { use FindBin; chdir($FindBin::Bin); }
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
17
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
18 use lib 'lib';
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
19 use Test::Nginx;
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
20
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
21 ###############################################################################
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
22
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
23 select STDERR; $| = 1;
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
24 select STDOUT; $| = 1;
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
25
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
26 my $t = Test::Nginx->new()->has(qw/http rewrite/)
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
27 ->write_file_expand('nginx.conf', <<'EOF');
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
28
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
29 %%TEST_GLOBALS%%
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
30
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
31 daemon off;
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
32
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
33 events {
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
34 }
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
35
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
36 http {
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
37 %%TEST_GLOBALS_HTTP%%
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
38
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1617
diff changeset
39 js_import test.js;
1534
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
40
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
41 server {
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
42 listen 127.0.0.1:8080;
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
43 server_name localhost;
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
44
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
45 location /dump {
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1617
diff changeset
46 js_content test.dump;
1534
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
47 }
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
48
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
49 location /stringify {
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1617
diff changeset
50 js_content test.stringify;
1534
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
51 }
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
52
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
53 location /stringify_subrequest {
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1617
diff changeset
54 js_content test.stringify_subrequest;
1534
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
55 }
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
56
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
57 location /js_sub {
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
58 return 201 '{$request_method}';
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
59 }
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
60 }
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
61 }
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
62
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
63 EOF
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
64
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
65 $t->write_file('test.js', <<EOF);
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1617
diff changeset
66 function dump(r) {
1534
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
67 r.headersOut.baz = 'bar';
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
68 r.return(200, njs.dump(r));
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
69 }
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
70
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1617
diff changeset
71 function stringify(r) {
1534
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
72 r.headersOut.baz = 'bar';
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
73 var obj = JSON.parse(JSON.stringify(r));
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
74 r.return(200, JSON.stringify(obj));
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
75 }
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
76
1751
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1617
diff changeset
77 function stringify_subrequest(r) {
1534
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
78 r.subrequest('/js_sub', reply => {
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
79 r.return(200, JSON.stringify(reply))
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
80 });
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
81 }
96fb3513345b Tests: added js dump tests.
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: 1617
diff changeset
83 export default {dump, stringify, stringify_subrequest};
18ac4d9e5a2a Tests: rewriting njs tests without deprecated "js_include".
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1617
diff changeset
84
1534
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
85 EOF
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
86
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
87 $t->try_run('no njs dump')->plan(3);
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
88
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
89 ###############################################################################
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
90
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
91 like(http(
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
92 'GET /dump?v=1&t=x HTTP/1.0' . CRLF
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
93 . 'Foo: bar' . CRLF
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
94 . 'Foo2: bar2' . CRLF
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
95 . 'Host: localhost' . CRLF . CRLF
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
96 ), qr/method:'GET'/, 'njs.dump(r)');
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
97
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
98 like(http(
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
99 'GET /stringify?v=1&t=x HTTP/1.0' . CRLF
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
100 . 'Foo: bar' . CRLF
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
101 . 'Foo2: bar2' . CRLF
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
102 . 'Host: localhost' . CRLF . CRLF
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
103 ), qr/headersOut":\{"baz":"bar"}/, 'JSON.stringify(r)');
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
104
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
105 like(http(
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
106 'GET /stringify_subrequest HTTP/1.0' . CRLF
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
107 . 'Host: localhost' . CRLF . CRLF
1617
c56df3527161 Tests: adapted js_dump.t to upcoming changes in 0.5.0.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1614
diff changeset
108 ), qr/"status":201/, 'JSON.stringify(reply)');
1534
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
109
96fb3513345b Tests: added js dump tests.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
diff changeset
110 ###############################################################################