annotate stream_js.t @ 1738:9e0347f4df11

Tests: added js tests for async functions.
author Dmitry Volyntsev <xeioex@nginx.com>
date Mon, 11 Oct 2021 14:34:54 +0000
parents cd35d4f44937
children 18ac4d9e5a2a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
1 #!/usr/bin/perl
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
2
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
3 # (C) Andrey Zelenkov
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
4 # (C) Dmitry Volyntsev
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
5 # (C) Nginx, Inc.
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
6
1375
f168fc46c7a4 Tests: renamed JavaScript to njs.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1374
diff changeset
7 # Tests for stream njs module.
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
8
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
9 ###############################################################################
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
10
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
11 use warnings;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
12 use strict;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
13
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
14 use Test::More;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
15
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
16 BEGIN { use FindBin; chdir($FindBin::Bin); }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
17
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
18 use lib 'lib';
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
19 use Test::Nginx;
1005
557faa1782e5 Tests: stream JavaScript test with udp.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1003
diff changeset
20 use Test::Nginx::Stream qw/ dgram stream /;
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
21
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
22 ###############################################################################
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
23
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
24 select STDERR; $| = 1;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
25 select STDOUT; $| = 1;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
26
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
27 my $t = Test::Nginx->new()->has(qw/http proxy rewrite stream stream_return udp/)
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
28 ->write_file_expand('nginx.conf', <<'EOF');
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
29
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
30 %%TEST_GLOBALS%%
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
31
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
32 daemon off;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
33
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
34 events {
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
35 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
36
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
37 http {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
38 %%TEST_GLOBALS_HTTP%%
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
39
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
40 js_include test.js;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
41
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
42 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
43 listen 127.0.0.1:8079;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
44 server_name localhost;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
45
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
46 location /njs {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
47 js_content test_njs;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
48 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
49
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
50 location /p/ {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
51 proxy_pass http://127.0.0.1:8095/;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
52
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
53 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
54
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
55 location /return {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
56 return 200 $http_foo;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
57 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
58 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
59 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
60
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
61 stream {
1609
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1544
diff changeset
62 %%TEST_GLOBALS_STREAM%%
f3ba4c74de31 Tests: added TEST_GLOBALS_STREAM variable support.
Andrei Belov <defan@nginx.com>
parents: 1544
diff changeset
63
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
64 js_set $js_addr js_addr;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
65 js_set $js_var js_var;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
66 js_set $js_log js_log;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
67 js_set $js_unk js_unk;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
68 js_set $js_req_line js_req_line;
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
69 js_set $js_sess_unk js_sess_unk;
1738
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
70 js_set $js_async js_async;
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
71
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
72 js_include test.js;
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
73
1643
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
74 log_format status $server_port:$status;
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
75
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
76 server {
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
77 listen 127.0.0.1:8080;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
78 return $js_addr;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
79 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
80
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
81 server {
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
82 listen 127.0.0.1:8081;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
83 return $js_log;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
84 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
85
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
86 server {
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
87 listen 127.0.0.1:8082;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
88 return $js_var;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
89 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
90
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
91 server {
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
92 listen 127.0.0.1:8083;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
93 return $js_unk;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
94 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
95
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
96 server {
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
97 listen 127.0.0.1:8084;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
98 return $js_sess_unk;
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
99 }
1005
557faa1782e5 Tests: stream JavaScript test with udp.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1003
diff changeset
100
557faa1782e5 Tests: stream JavaScript test with udp.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1003
diff changeset
101 server {
1237
e4974af3fb12 Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1005
diff changeset
102 listen 127.0.0.1:%%PORT_8985_UDP%% udp;
1005
557faa1782e5 Tests: stream JavaScript test with udp.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1003
diff changeset
103 return $js_addr;
557faa1782e5 Tests: stream JavaScript test with udp.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1003
diff changeset
104 }
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
105
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
106 server {
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
107 listen 127.0.0.1:8086;
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
108 js_access js_access_step;
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
109 js_preread js_preread_step;
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
110 js_filter js_filter_step;
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
111 proxy_pass 127.0.0.1:8090;
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
112 }
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
113
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
114 server {
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
115 listen 127.0.0.1:8087;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
116 js_access js_access_undecided;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
117 return OK;
1643
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
118 access_log %%TESTDIR%%/status.log status;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
119 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
120
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
121 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
122 listen 127.0.0.1:8088;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
123 js_access js_access_allow;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
124 return OK;
1643
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
125 access_log %%TESTDIR%%/status.log status;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
126 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
127
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
128 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
129 listen 127.0.0.1:8089;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
130 js_access js_access_deny;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
131 return OK;
1643
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
132 access_log %%TESTDIR%%/status.log status;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
133 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
134
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
135 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
136 listen 127.0.0.1:8091;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
137 js_preread js_preread_async;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
138 proxy_pass 127.0.0.1:8090;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
139 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
140
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
141 server {
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
142 listen 127.0.0.1:8092;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
143 js_preread js_preread_data;
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
144 proxy_pass 127.0.0.1:8090;
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
145 }
1248
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
146
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
147 server {
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
148 listen 127.0.0.1:8093;
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
149 js_preread js_preread_req_line;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
150 return $js_req_line;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
151 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
152
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
153 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
154 listen 127.0.0.1:8094;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
155 js_filter js_filter_empty;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
156 proxy_pass 127.0.0.1:8090;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
157 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
158
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
159 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
160 listen 127.0.0.1:8095;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
161 js_filter js_filter_header_inject;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
162 proxy_pass 127.0.0.1:8079;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
163 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
164
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
165 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
166 listen 127.0.0.1:8096;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
167 js_filter js_filter_search;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
168 proxy_pass 127.0.0.1:8090;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
169 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
170
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
171 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
172 listen 127.0.0.1:8097;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
173 js_access js_access_except;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
174 proxy_pass 127.0.0.1:8090;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
175 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
176
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
177 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
178 listen 127.0.0.1:8098;
1248
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
179 js_preread js_preread_except;
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
180 proxy_pass 127.0.0.1:8090;
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
181 }
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
182
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
183 server {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
184 listen 127.0.0.1:8099;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
185 js_filter js_filter_except;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
186 proxy_pass 127.0.0.1:8090;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
187 }
1738
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
188
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
189 server {
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
190 listen 127.0.0.1:8100;
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
191 return $js_async;
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
192 }
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
193 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
194
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
195 EOF
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
196
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
197 $t->write_file('test.js', <<EOF);
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
198 function test_njs(r) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
199 r.return(200, njs.version);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
200 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
201
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
202 function js_addr(s) {
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
203 return 'addr=' + s.remoteAddress;
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
204 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
205
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
206 function js_var(s) {
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
207 return 'variable=' + s.variables.remote_addr;
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
208 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
209
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
210 function js_sess_unk(s) {
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
211 return 'sess_unk=' + s.unk;
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
212 }
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
213
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
214 function js_log(s) {
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
215 s.log("SEE-THIS");
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
216 }
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
217
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
218 var res = '';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
219
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
220 function js_access_step(s) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
221 res += '1';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
222
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
223 setTimeout(function() {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
224 if (s.remoteAddress.match('127.0.0.1')) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
225 s.allow();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
226 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
227 }, 1);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
228 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
229
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
230 function js_preread_step(s) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
231 s.on('upload', function (data) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
232 res += '2';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
233 if (res.length >= 3) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
234 s.done();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
235 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
236 });
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
237 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
238
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
239 function js_filter_step(s) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
240 s.on('upload', function(data, flags) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
241 s.send(data);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
242 res += '3';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
243 });
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
244
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
245 s.on('download', function(data, flags) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
246
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
247 if (!flags.last) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
248 res += '4';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
249 s.send(data);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
250
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
251 } else {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
252 res += '5';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
253 s.send(res, {last:1});
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
254 s.off('download');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
255 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
256 });
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
257 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
258
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
259 function js_access_undecided(s) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
260 s.decline();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
261 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
262
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
263 function js_access_allow(s) {
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
264 if (s.remoteAddress.match('127.0.0.1')) {
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
265 s.done();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
266 return;
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
267 }
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
268
1643
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
269 s.deny();
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
270 }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
271
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
272 function js_access_deny(s) {
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
273 if (s.remoteAddress.match('127.0.0.1')) {
1643
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
274 s.deny();
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
275 return;
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
276 }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
277
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
278 s.allow();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
279 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
280
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
281
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
282 function js_preread_async(s) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
283 setTimeout(function() {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
284 s.done();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
285 }, 1);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
286 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
287
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
288 function js_preread_data(s) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
289 s.on('upload', function (data, flags) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
290 if (data.indexOf('z') != -1) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
291 s.done();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
292 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
293 });
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
294 }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
295
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
296 var line = '';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
297
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
298 function js_preread_req_line(s) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
299 s.on('upload', function (data, flags) {
1441
2e81f7788cf7 Tests: adapted stream_js.t to njs changes.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1375
diff changeset
300 var n = data.indexOf('\\n');
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
301 if (n != -1) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
302 line = data.substr(0, n);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
303 s.done();
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
304 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
305 });
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
306 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
307
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
308 function js_req_line(s) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
309 return line;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
310 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
311
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
312 function js_filter_empty(s) {
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
313 }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
314
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
315 function js_filter_header_inject(s) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
316 var req = '';
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
317
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
318 s.on('upload', function(data, flags) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
319 req += data;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
320
1441
2e81f7788cf7 Tests: adapted stream_js.t to njs changes.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1375
diff changeset
321 var n = req.search('\\n');
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
322 if (n != -1) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
323 var rest = req.substr(n + 1);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
324 req = req.substr(0, n + 1);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
325
1441
2e81f7788cf7 Tests: adapted stream_js.t to njs changes.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1375
diff changeset
326 s.send(req + 'Foo: foo' + '\\r\\n' + rest, flags);
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
327
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
328 s.off('upload');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
329 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
330 });
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
331 }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
332
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
333 function js_filter_search(s) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
334 s.on('download', function(data, flags) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
335 var n = data.search('y');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
336 if (n != -1) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
337 s.send('z');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
338 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
339 });
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
340
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
341 s.on('upload', function(data, flags) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
342 var n = data.search('x');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
343 if (n != -1) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
344 s.send('y');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
345 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
346 });
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
347 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
348
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
349 function js_access_except(s) {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
350 function done() {return s.a.a};
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
351
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
352 setTimeout(done, 1);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
353 setTimeout(done, 2);
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
354 }
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
355
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
356 function js_preread_except(s) {
1248
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
357 var fs = require('fs');
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
358 fs.readFileSync();
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
359 }
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
360
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
361 function js_filter_except(s) {
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
362 s.on('unknown', function() {});
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
363 }
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
364
1738
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
365 function pr(x) {
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
366 return new Promise(resolve => {resolve(x)}).then(v => v).then(v => v);
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
367 }
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
368
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
369 async function js_async(s) {
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
370 const a1 = await pr(10);
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
371 const a2 = await pr(20);
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
372
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
373 s.setReturnValue(`retval: \${a1 + a2}`);
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
374 }
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
375
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
376 EOF
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
377
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
378 $t->run_daemon(\&stream_daemon, port(8090));
1738
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
379 $t->try_run('no stream njs available')->plan(23);
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
380 $t->waitforsocket('127.0.0.1:' . port(8090));
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
381
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
382 ###############################################################################
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
383
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
384 is(stream('127.0.0.1:' . port(8080))->read(), 'addr=127.0.0.1',
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
385 's.remoteAddress');
1237
e4974af3fb12 Tests: adjusted udp ports to match allocated ports range.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1005
diff changeset
386 is(dgram('127.0.0.1:' . port(8985))->io('.'), 'addr=127.0.0.1',
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
387 's.remoteAddress udp');
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
388 is(stream('127.0.0.1:' . port(8081))->read(), 'undefined', 's.log');
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
389 is(stream('127.0.0.1:' . port(8082))->read(), 'variable=127.0.0.1',
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
390 's.variables');
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
391 is(stream('127.0.0.1:' . port(8083))->read(), '', 'stream js unknown function');
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
392 is(stream('127.0.0.1:' . port(8084))->read(), 'sess_unk=undefined', 's.unk');
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
393
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
394 is(stream('127.0.0.1:' . port(8086))->io('0'), '0122345',
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
395 'async handlers order');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
396 is(stream('127.0.0.1:' . port(8087))->io('#'), 'OK', 'js_access_undecided');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
397 is(stream('127.0.0.1:' . port(8088))->io('#'), 'OK', 'js_access_allow');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
398 is(stream('127.0.0.1:' . port(8089))->io('#'), '', 'js_access_deny');
1373
0569baf0cc4a Tests: style.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1315
diff changeset
399
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
400 is(stream('127.0.0.1:' . port(8091))->io('#'), '#', 'js_preread_async');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
401 is(stream('127.0.0.1:' . port(8092))->io('#z'), '#z', 'js_preread_async_data');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
402 is(stream('127.0.0.1:' . port(8093))->io("xy\na"), 'xy', 'js_preread_req_line');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
403
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
404 is(stream('127.0.0.1:' . port(8094))->io('x'), 'x', 'js_filter_empty');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
405 like(get('/p/return'), qr/foo/, 'js_filter_injected_header');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
406 is(stream('127.0.0.1:' . port(8096))->io('x'), 'z', 'js_filter_search');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
407
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
408 stream('127.0.0.1:' . port(8097))->io('x');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
409 stream('127.0.0.1:' . port(8098))->io('x');
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
410 stream('127.0.0.1:' . port(8099))->io('x');
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
411
1738
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
412 TODO: {
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
413 local $TODO = 'not yet'
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
414 unless get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.0';
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
415
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
416 is(stream('127.0.0.1:' . port(8100))->read(), 'retval: 30', 'js_async');
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
417
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
418 }
9e0347f4df11 Tests: added js tests for async functions.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1643
diff changeset
419
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
420 $t->stop();
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
421
1315
890516ca898a Tests: reverted 3882f8f3b2bc to unbreak with njs 0.1.15.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1310
diff changeset
422 ok(index($t->read_file('error.log'), 'SEE-THIS') > 0, 'stream js log');
1248
70192b1baf01 Tests: added exception test to stream_js.t using 'require'.
Sergey Kandaurov <pluknet@nginx.com>
parents: 1247
diff changeset
423 ok(index($t->read_file('error.log'), 'at fs.readFileSync') > 0,
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
424 'stream js_preread backtrace');
1247
edf5a3c9e36a Tests: added tests for js backtraces.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1239
diff changeset
425 ok(index($t->read_file('error.log'), 'at js_filter_except') > 0,
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
426 'stream js_filter backtrace');
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
427
1643
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
428 my @p = (port(8087), port(8088), port(8089));
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
429 like($t->read_file('status.log'), qr/$p[0]:200/, 'status undecided');
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
430 like($t->read_file('status.log'), qr/$p[1]:200/, 'status allow');
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
431 like($t->read_file('status.log'), qr/$p[2]:403/, 'status deny');
cd35d4f44937 Tests: fixed typo in stream_js.t introduced in fd7766ab0a69.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1609
diff changeset
432
1003
a86034bcbe82 Tests: stream JavaScript tests.
Andrey Zelenkov <zelenkov@nginx.com>
parents:
diff changeset
433 ###############################################################################
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
434
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
435 sub stream_daemon {
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
436 my $server = IO::Socket::INET->new(
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
437 Proto => 'tcp',
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
438 LocalAddr => '127.0.0.1:' . port(8090),
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
439 Listen => 5,
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
440 Reuse => 1
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
441 )
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
442 or die "Can't create listening socket: $!\n";
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
443
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
444 local $SIG{PIPE} = 'IGNORE';
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
445
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
446 while (my $client = $server->accept()) {
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
447 $client->autoflush(1);
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
448
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
449 log2c("(new connection $client)");
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
450
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
451 $client->sysread(my $buffer, 65536) or next;
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
452
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
453 log2i("$client $buffer");
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
454
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
455 log2o("$client $buffer");
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
456
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
457 $client->syswrite($buffer);
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
458
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
459 close $client;
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
460 }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
461 }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
462
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
463 sub log2i { Test::Nginx::log_core('|| <<', @_); }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
464 sub log2o { Test::Nginx::log_core('|| >>', @_); }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
465 sub log2c { Test::Nginx::log_core('||', @_); }
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
466
1374
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
467 sub get {
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
468 my ($url, %extra) = @_;
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
469
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
470 my $s = IO::Socket::INET->new(
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
471 Proto => 'tcp',
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
472 PeerAddr => '127.0.0.1:' . port(8079)
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
473 ) or die "Can't connect to nginx: $!\n";
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
474
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
475 return http_get($url, socket => $s);
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
476 }
fd7766ab0a69 Tests: stream njs module refactored.
Dmitry Volyntsev <xeioex@nginx.com>
parents: 1373
diff changeset
477
1239
4a825ec85c8d Tests: added tests for js_access, js_preread, and js_filter.
Andrey Zelenkov <zelenkov@nginx.com>
parents: 1237
diff changeset
478 ###############################################################################