Mercurial > hg > nginx-tests
comparison js_subrequests.t @ 1554:cae83c98654a
Tests: added detached subrequest js tests.
author | Dmitry Volyntsev <xeioex@nginx.com> |
---|---|
date | Mon, 02 Mar 2020 21:10:59 +0300 |
parents | 01867708af95 |
children | b194552fcc21 |
comparison
equal
deleted
inserted
replaced
1553:01867708af95 | 1554:cae83c98654a |
---|---|
43 proxy_cache_path %%TESTDIR%%/cache1 | 43 proxy_cache_path %%TESTDIR%%/cache1 |
44 keys_zone=ON:1m use_temp_path=on; | 44 keys_zone=ON:1m use_temp_path=on; |
45 | 45 |
46 js_include test.js; | 46 js_include test.js; |
47 | 47 |
48 js_set $async_var async_var; | 48 js_set $async_var async_var; |
49 js_set $subrequest_var subrequest_var; | |
49 | 50 |
50 server { | 51 server { |
51 listen 127.0.0.1:8080; | 52 listen 127.0.0.1:8080; |
52 server_name localhost; | 53 server_name localhost; |
53 | 54 |
104 } | 105 } |
105 | 106 |
106 location /sr_in_variable_handler { | 107 location /sr_in_variable_handler { |
107 set $_ $async_var; | 108 set $_ $async_var; |
108 js_content sr_in_variable_handler; | 109 js_content sr_in_variable_handler; |
110 } | |
111 | |
112 location /sr_detached_in_variable_handler { | |
113 return 200 $subrequest_var; | |
109 } | 114 } |
110 | 115 |
111 location /sr_error_page { | 116 location /sr_error_page { |
112 set $_ $async_var; | 117 set $_ $async_var; |
113 error_page 404 /return; | 118 error_page 404 /return; |
232 return 200 '["$request_method"]'; | 237 return 200 '["$request_method"]'; |
233 } | 238 } |
234 | 239 |
235 location /body { | 240 location /body { |
236 js_content body; | 241 js_content body; |
242 } | |
243 | |
244 location /detached { | |
245 js_content detached; | |
237 } | 246 } |
238 | 247 |
239 location /delayed { | 248 location /delayed { |
240 js_content delayed; | 249 js_content delayed; |
241 } | 250 } |
320 r.return(200, r.variables.request_body); | 329 r.return(200, r.variables.request_body); |
321 } | 330 } |
322 | 331 |
323 function delayed(r) { | 332 function delayed(r) { |
324 setTimeout(r => r.return(200), 100, r); | 333 setTimeout(r => r.return(200), 100, r); |
325 } | 334 } |
335 | |
336 function detached(r) { | |
337 var method = r.variables.request_method; | |
338 r.log(`DETACHED: \${method} args: \${r.variables.args}`); | |
339 | |
340 r.return(200); | |
341 } | |
326 | 342 |
327 function sr_in_variable_handler(r) { | 343 function sr_in_variable_handler(r) { |
328 } | 344 } |
329 | 345 |
330 function async_var(r) { | 346 function async_var(r) { |
333 }); | 349 }); |
334 | 350 |
335 return ""; | 351 return ""; |
336 } | 352 } |
337 | 353 |
354 function subrequest_var(r) { | |
355 r.subrequest('/p/detached', {detached:true}); | |
356 r.subrequest('/p/detached', {detached:true, args:'a=yyy', | |
357 method:'POST'}); | |
358 | |
359 return "subrequest_var"; | |
360 } | |
361 | |
338 function sr_file(r) { | 362 function sr_file(r) { |
339 r.subrequest('/file/t', body_fwd_cb); | 363 r.subrequest('/file/t', body_fwd_cb); |
340 } | 364 } |
341 | 365 |
342 function sr_cache(r) { | 366 function sr_cache(r) { |
459 | 483 |
460 EOF | 484 EOF |
461 | 485 |
462 $t->write_file('t', '["SEE-THIS"]'); | 486 $t->write_file('t', '["SEE-THIS"]'); |
463 | 487 |
464 $t->try_run('no njs available')->plan(29); | 488 $t->try_run('no njs available')->plan(31); |
465 $t->run_daemon(\&http_daemon); | 489 $t->run_daemon(\&http_daemon); |
466 | 490 |
467 ############################################################################### | 491 ############################################################################### |
468 | 492 |
469 is(get_json('/sr'), '[{"status":404,"uri":"/p/sub2"}]', 'sr'); | 493 is(get_json('/sr'), '[{"status":404,"uri":"/p/sub2"}]', 'sr'); |
500 '[{"status":404,"uri":"/unknown"},' . | 524 '[{"status":404,"uri":"/unknown"},' . |
501 '{"status":206,"uri":"/p/sub1"},' . | 525 '{"status":206,"uri":"/p/sub1"},' . |
502 '{"status":200,"uri":"/p/delayed"}]', | 526 '{"status":200,"uri":"/p/delayed"}]', |
503 'sr_multi'); | 527 'sr_multi'); |
504 | 528 |
529 my $ver = http_get('/njs'); | |
530 | |
505 TODO: { | 531 TODO: { |
506 local $TODO = 'not yet' | 532 local $TODO = 'not yet' |
507 unless http_get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.3.8'; | 533 unless $ver =~ /^([.0-9]+)$/m && $1 ge '0.3.8'; |
508 | 534 |
509 is(get_json('/sr_pr'), '{"h":"xxx"}', 'sr_promise'); | 535 is(get_json('/sr_pr'), '{"h":"xxx"}', 'sr_promise'); |
510 is(get_json('/sr_options_args_pr'), '{"h":"xxx"}', 'sr_options_args_pr'); | 536 is(get_json('/sr_options_args_pr'), '{"h":"xxx"}', 'sr_options_args_pr'); |
511 is(get_json('/sr_options_method_pr?m=PUT'), '["PUT"]', 'sr method PUT'); | 537 is(get_json('/sr_options_method_pr?m=PUT'), '["PUT"]', 'sr method PUT'); |
512 is(get_json('/sr_body_pr'), '{"a":{"b":1}}', 'sr_body_pr'); | 538 is(get_json('/sr_body_pr'), '{"a":{"b":1}}', 'sr_body_pr'); |
513 is(get_json('/sr_js_in_subrequest_pr'), '["JS-SUB"]', 'sr_js_in_subrequest_pr'); | 539 is(get_json('/sr_js_in_subrequest_pr'), '["JS-SUB"]', 'sr_js_in_subrequest_pr'); |
514 is(get_json('/sr_unavail_pr'), '[{"status":502,"uri":"/unavail"}]', | 540 is(get_json('/sr_unavail_pr'), '[{"status":502,"uri":"/unavail"}]', |
515 'sr_unavail_pr'); | 541 'sr_unavail_pr'); |
516 | 542 |
543 } | |
544 | |
545 TODO: { | |
546 local $TODO = 'not yet' | |
547 unless $ver =~ /^([.0-9]+)$/m && $1 ge '0.3.9'; | |
548 | |
549 like(http_get('/sr_detached_in_variable_handler'), qr/subrequest_var/, | |
550 'sr_detached_in_variable_handler'); | |
517 } | 551 } |
518 | 552 |
519 http_get('/sr_broken'); | 553 http_get('/sr_broken'); |
520 http_get('/sr_in_sr'); | 554 http_get('/sr_in_sr'); |
521 http_get('/sr_in_variable_handler'); | 555 http_get('/sr_in_variable_handler'); |
544 'subrequest creation failed'); | 578 'subrequest creation failed'); |
545 ok(index($t->read_file('error.log'), | 579 ok(index($t->read_file('error.log'), |
546 'js subrequest: failed to get the parent context') > 0, | 580 'js subrequest: failed to get the parent context') > 0, |
547 'zero parent ctx'); | 581 'zero parent ctx'); |
548 | 582 |
583 TODO: { | |
584 local $TODO = 'not yet' | |
585 unless $ver =~ /^([.0-9]+)$/m && $1 ge '0.3.9'; | |
586 | |
587 ok(index($t->read_file('error.log'), 'DETACHED') > 0, | |
588 'detached subrequest'); | |
589 } | |
590 | |
549 ############################################################################### | 591 ############################################################################### |
550 | 592 |
551 sub recode { | 593 sub recode { |
552 my $json; | 594 my $json; |
553 eval { $json = JSON::PP::decode_json(shift) }; | 595 eval { $json = JSON::PP::decode_json(shift) }; |