Skip to content

Commit 05d58a9

Browse files
committed
Tests: added tests for js backtraces.
1 parent 177ff31 commit 05d58a9

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

js.t

+27-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ http {
4444
js_set $test_iarg test_iarg;
4545
js_set $test_var test_var;
4646
js_set $test_log test_log;
47+
js_set $test_except test_except;
4748
4849
js_include test.js;
4950
@@ -91,6 +92,10 @@ http {
9192
return 200 $test_log;
9293
}
9394
95+
location /req_except {
96+
return 200 $test_except;
97+
}
98+
9499
location /res_status {
95100
js_content status;
96101
}
@@ -114,6 +119,10 @@ http {
114119
location /res_ihdr {
115120
js_content ihdr;
116121
}
122+
123+
location /res_except {
124+
js_content content_except;
125+
}
117126
}
118127
}
119128
@@ -172,6 +181,11 @@ $t->write_file('test.js', <<EOF);
172181
req.log("SEE-THIS");
173182
}
174183
184+
function test_except(req, res) {
185+
var fs = require('fs');
186+
fs.readFileSync();
187+
}
188+
175189
function status(req, res) {
176190
res.status = 204;
177191
if (res.status != 204)
@@ -240,9 +254,14 @@ $t->write_file('test.js', <<EOF);
240254
res.send(s);
241255
res.finish();
242256
}
257+
258+
function content_except(req, res) {
259+
JSON.parse({}.a.a);
260+
}
261+
243262
EOF
244263

245-
$t->try_run('no njs available')->plan(20);
264+
$t->try_run('no njs available')->plan(22);
246265

247266
###############################################################################
248267

@@ -269,6 +288,9 @@ like(http_get('/res_hdr?foo=123&bar=copy'), qr/Bar: 123/, 'res.headers get');
269288
like(http_get('/res_hdr?bar=empty'), qr/Bar: \x0d/, 'res.headers empty');
270289
like(http_get('/res_ihdr?a=12&b=34'), qr/^1234$/m, 'res.headers iteration');
271290

291+
http_get('/req_except');
292+
http_get('/res_except');
293+
272294
TODO: {
273295
local $TODO = 'zero size buf in writer';
274296

@@ -281,6 +303,10 @@ $t->todo_alerts();
281303
$t->stop();
282304

283305
ok(index($t->read_file('error.log'), 'SEE-THIS') > 0, 'log js');
306+
ok(index($t->read_file('error.log'), 'at fs.readFileSync') > 0,
307+
'js_set backtrace');
308+
ok(index($t->read_file('error.log'), 'at JSON.parse') > 0,
309+
'js_content backtrace');
284310

285311
###############################################################################
286312

stream_js.t

+15-1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ stream {
103103
js_filter js_filter_step;
104104
proxy_pass 127.0.0.1:8090;
105105
}
106+
107+
server {
108+
listen 127.0.0.1:8092;
109+
js_filter js_filter_except;
110+
proxy_pass 127.0.0.1:8090;
111+
}
106112
}
107113
108114
EOF
@@ -174,10 +180,15 @@ $t->write_file('functions.js', <<EOF);
174180
}
175181
res += '3';
176182
}
183+
184+
function js_filter_except(sess) {
185+
sess.a.a;
186+
}
187+
177188
EOF
178189

179190
$t->run_daemon(\&stream_daemon, port(8090));
180-
$t->try_run('no stream njs available')->plan(12);
191+
$t->try_run('no stream njs available')->plan(13);
181192
$t->waitforsocket('127.0.0.1:' . port(8090));
182193

183194
###############################################################################
@@ -196,10 +207,13 @@ is(stream('127.0.0.1:' . port(8087))->read(), '', 'js_access deny');
196207
is(stream('127.0.0.1:' . port(8088))->io('xyz'), 'xyz', 'js_preread');
197208
is(stream('127.0.0.1:' . port(8089))->io('x'), 'z', 'js_filter');
198209
is(stream('127.0.0.1:' . port(8091))->io('0'), '01233', 'handlers order');
210+
stream('127.0.0.1:' . port(8092))->io('x');
199211

200212
$t->stop();
201213

202214
ok(index($t->read_file('error.log'), 'SEE-THIS') > 0, 'stream js log');
215+
ok(index($t->read_file('error.log'), 'at js_filter_except') > 0,
216+
'stream js_filter backtrace');
203217

204218
###############################################################################
205219

0 commit comments

Comments
 (0)