Mercurial > hg > nginx-tests
annotate js_return.t @ 1677:f13ead27f89c
Tests: improved stop() to send TERM after QUIT.
It is possible that graceful stop as initiated by SIGQUIT will take
very long time, such as when waiting for proxy_timeout in mail proxy
(defaults to 24h). To make sure in such cases nginx is stopped after
some reasonable time, we now send SIGTERM after waiting for 90 seconds.
Note that win32 version previously used "-s stop", which is equivalent
to SIGTERM rather than SIGQUIT. This seems accidental error during
introduction of initial win32 support in tests (ce2e23daa1da), so
it is changed to follow the same logic.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 19 May 2021 04:32:55 +0300 |
parents | bc0990ea2e5b |
children | 18ac4d9e5a2a |
rev | line source |
---|---|
1317
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
1 #!/usr/bin/perl |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
2 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
3 # (C) Sergey Kandaurov |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
4 # (C) Nginx, Inc. |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
5 |
1375
f168fc46c7a4
Tests: renamed JavaScript to njs.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1320
diff
changeset
|
6 # Tests for http njs module, return method. |
1317
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
7 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
8 ############################################################################### |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
9 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
10 use warnings; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
11 use strict; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
12 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
13 use Test::More; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
14 |
1320
8bd4b88fcac5
Tests: TODO js_return.t fail seen with older njs on some platforms.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1317
diff
changeset
|
15 use Config; |
8bd4b88fcac5
Tests: TODO js_return.t fail seen with older njs on some platforms.
Sergey Kandaurov <pluknet@nginx.com>
parents:
1317
diff
changeset
|
16 |
1317
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
17 BEGIN { use FindBin; chdir($FindBin::Bin); } |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
18 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
19 use lib 'lib'; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
20 use Test::Nginx; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
21 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
22 ############################################################################### |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
23 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
24 select STDERR; $| = 1; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
25 select STDOUT; $| = 1; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
26 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
27 my $t = Test::Nginx->new()->has(qw/http/) |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
28 ->write_file_expand('nginx.conf', <<'EOF'); |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
29 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
30 %%TEST_GLOBALS%% |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
31 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
32 daemon off; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
33 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
34 events { |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
35 } |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
36 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
37 http { |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
38 %%TEST_GLOBALS_HTTP%% |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
39 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
40 js_include test.js; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
41 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
42 server { |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
43 listen 127.0.0.1:8080; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
44 server_name localhost; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
45 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
46 location / { |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
47 js_content test_return; |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
48 } |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
49 } |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
50 } |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
51 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
52 EOF |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
53 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
54 $t->write_file('test.js', <<EOF); |
1436
9d8b100a6ce3
Tests: get rid of deprecated njs API in 0.2.2.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1375
diff
changeset
|
55 function test_return(r) { |
9d8b100a6ce3
Tests: get rid of deprecated njs API in 0.2.2.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
1375
diff
changeset
|
56 r.return(Number(r.args.c), r.args.t); |
1317
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
57 } |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
58 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
59 EOF |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
60 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
61 $t->try_run('no njs return')->plan(5); |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
62 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
63 ############################################################################### |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
64 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
65 like(http_get('/?c=200'), qr/200 OK.*\x0d\x0a?\x0d\x0a?$/s, 'return code'); |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
66 like(http_get('/?c=200&t=SEE-THIS'), qr/200 OK.*^SEE-THIS$/ms, 'return text'); |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
67 like(http_get('/?c=301&t=path'), qr/ 301 .*Location: path/s, 'return redirect'); |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
68 like(http_get('/?c=404'), qr/404 Not.*html/s, 'return error page'); |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
69 like(http_get('/?c=inv'), qr/ 500 /, 'return invalid'); |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
70 |
a05f377bf0ca
Tests: added njs return tests.
Sergey Kandaurov <pluknet@nginx.com>
parents:
diff
changeset
|
71 ############################################################################### |