comparison js_subrequests.t @ 1359:28ba4b465635

Tests: more njs subrequest tests.
author Dmitry Volyntsev <xeioex@nginx.com>
date Wed, 25 Jul 2018 19:25:42 +0300
parents c582fa4c4a95
children f168fc46c7a4
comparison
equal deleted inserted replaced
1358:71f964c077bf 1359:28ba4b465635
49 49
50 server { 50 server {
51 listen 127.0.0.1:8080; 51 listen 127.0.0.1:8080;
52 server_name localhost; 52 server_name localhost;
53 53
54 location /njs {
55 js_content test_njs;
56 }
57
54 location /sr { 58 location /sr {
55 js_content sr; 59 js_content sr;
56 } 60 }
57 61
58 location /sr_args { 62 location /sr_args {
145 149
146 location /sr_except_invalid_options_header_only { 150 location /sr_except_invalid_options_header_only {
147 js_content sr_except_invalid_options_header_only; 151 js_content sr_except_invalid_options_header_only;
148 } 152 }
149 153
154 location /sr_js_in_sr_parent {
155 js_content sr_js_in_sr_parent;
156 }
157
158 location /sr_in_sr_callback {
159 js_content sr_in_sr_callback;
160 }
161
150 location /sr_uri_except { 162 location /sr_uri_except {
151 js_content sr_uri_except; 163 js_content sr_uri_except;
152 } 164 }
153 165
154 166
176 188
177 location /unavail { 189 location /unavail {
178 proxy_pass http://127.0.0.1:8084/; 190 proxy_pass http://127.0.0.1:8084/;
179 } 191 }
180 192
193 location /sr_parent {
194 js_content sr_parent;
195 }
196
181 location /js_sub { 197 location /js_sub {
182 js_content js_sub; 198 js_content js_sub;
183 } 199 }
184 200
185 location /return { 201 location /return {
226 } 242 }
227 243
228 EOF 244 EOF
229 245
230 $t->write_file('test.js', <<EOF); 246 $t->write_file('test.js', <<EOF);
247 function test_njs(r) {
248 r.return(200, njs.version);
249 }
231 250
232 function sr(req) { 251 function sr(req) {
233 subrequest_fn(req, ['/p/sub2'], ['uri', 'status']) 252 subrequest_fn(req, ['/p/sub2'], ['uri', 'status'])
234 } 253 }
235 254
355 req.subrequest('/sr', body_fwd_cb); 374 req.subrequest('/sr', body_fwd_cb);
356 } 375 }
357 376
358 function sr_js_in_subrequest(req, res) { 377 function sr_js_in_subrequest(req, res) {
359 req.subrequest('/js_sub', body_fwd_cb); 378 req.subrequest('/js_sub', body_fwd_cb);
379 }
380
381 function sr_js_in_sr_parent(r) {
382 r.subrequest('/sr_parent', body_fwd_cb);
383 }
384
385 function sr_in_sr_callback(r) {
386 r.subrequest('/return', function (reply) {
387 try {
388 reply.subrequest('/return');
389
390 } catch (err) {
391 r.return(200, JSON.stringify({e:err.message}));
392 return;
393 }
394
395 r.return(200);
396 });
397 }
398
399 function sr_parent(r) {
400 try {
401 var parent = r.parent;
402
403 } catch (err) {
404 r.return(200, JSON.stringify({e:err.message}));
405 return;
406 }
407
408 r.return(200);
360 } 409 }
361 410
362 function sr_out_of_order(req) { 411 function sr_out_of_order(req) {
363 subrequest_fn(req, ['/p/delayed', '/p/sub1', '/unknown'], 412 subrequest_fn(req, ['/p/delayed', '/p/sub1', '/unknown'],
364 ['uri', 'status']); 413 ['uri', 'status']);
425 474
426 EOF 475 EOF
427 476
428 $t->write_file('t', '["SEE-THIS"]'); 477 $t->write_file('t', '["SEE-THIS"]');
429 478
430 $t->try_run('no njs available')->plan(23); 479 $t->try_run('no njs available')->plan(25);
431 $t->run_daemon(\&http_daemon); 480 $t->run_daemon(\&http_daemon);
432 481
433 ############################################################################### 482 ###############################################################################
434 483
435 is(get_json('/sr'), '[{"status":404,"uri":"/p/sub2"}]', 'sr'); 484 is(get_json('/sr'), '[{"status":404,"uri":"/p/sub2"}]', 'sr');
465 http_get('/sr_except_failed_to_convert_arg'); 514 http_get('/sr_except_failed_to_convert_arg');
466 http_get('/sr_except_failed_to_convert_options_arg'); 515 http_get('/sr_except_failed_to_convert_options_arg');
467 http_get('/sr_except_invalid_options_method'); 516 http_get('/sr_except_invalid_options_method');
468 http_get('/sr_uri_except'); 517 http_get('/sr_uri_except');
469 518
519 TODO: {
520 local $TODO = 'not yet'
521 unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.2.4';
522
523 is(get_json('/sr_js_in_sr_parent'),
524 '{"e":"parent can only be returned for a subrequest"}',
525 'parent in subrequest js_content');
526
527 todo_skip 'leaves coredump', 1
528 unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.2.4';
529
530 is(get_json('/sr_in_sr_callback'),
531 '{"e":"subrequest can only be created for the primary request"}',
532 'subrequest for non-primary request');
533
534 }
535
470 $t->stop(); 536 $t->stop();
471 537
472 ok(index($t->read_file('error.log'), 'callback is not a function') > 0, 538 ok(index($t->read_file('error.log'), 'callback is not a function') > 0,
473 'subrequest cb exception'); 539 'subrequest cb exception');
474 ok(index($t->read_file('error.log'), 'failed to convert uri arg') > 0, 540 ok(index($t->read_file('error.log'), 'failed to convert uri arg') > 0,