diff options
Diffstat (limited to 'nginx/t')
-rw-r--r-- | nginx/t/js_fetch.t | 23 | ||||
-rw-r--r-- | nginx/t/js_internal_redirect.t | 29 | ||||
-rw-r--r-- | nginx/t/js_periodic.t | 2 | ||||
-rw-r--r-- | nginx/t/js_periodic_fetch.t | 9 |
4 files changed, 54 insertions, 9 deletions
diff --git a/nginx/t/js_fetch.t b/nginx/t/js_fetch.t index 1c6fde77..76d9238d 100644 --- a/nginx/t/js_fetch.t +++ b/nginx/t/js_fetch.t @@ -64,6 +64,10 @@ http { js_content test.body; } + location /body_content_length { + js_content test.body_content_length; + } + location /body_special { js_content test.body_special; } @@ -156,6 +160,13 @@ $t->write_file('test.js', <<EOF); .catch(e => r.return(501, e.message)) } + async function body_content_length(r) { + let resp = await ngx.fetch(`http://127.0.0.1:$p0/loc`, + {headers: {'Content-Length': '100'}, + body: "CONTENT-BODY"}); + r.return(resp.status); + } + function property(r) { var opts = {headers:{}}; @@ -400,12 +411,12 @@ $t->write_file('test.js', <<EOF); export default {njs: test_njs, body, broken, broken_response, body_special, chain, chunked_ok, chunked_fail, header, header_iter, - host_header, multi, loc, property}; + host_header, multi, loc, property, body_content_length }; EOF $t->try_run('no njs.fetch'); -$t->plan(37); +$t->plan(38); $t->run_daemon(\&http_daemon, port(8082)); $t->waitforsocket('127.0.0.1:' . port(8082)); @@ -508,6 +519,14 @@ like(http_get('/body_special?loc=head/large&method=HEAD'), qr/200 OK.*<empty>$/s, 'fetch head method large content-length'); } +TODO: { +local $TODO = 'not yet' unless has_version('0.9.1'); + +like(http_get('/body_content_length'), qr/200 OK/s, + 'fetch body content-length'); + +} + ############################################################################### sub has_version { diff --git a/nginx/t/js_internal_redirect.t b/nginx/t/js_internal_redirect.t index abfe79f9..721113bb 100644 --- a/nginx/t/js_internal_redirect.t +++ b/nginx/t/js_internal_redirect.t @@ -11,6 +11,7 @@ use warnings; use strict; use Test::More; +use Socket qw/ CRLF /; BEGIN { use FindBin; chdir($FindBin::Bin); } @@ -54,6 +55,10 @@ http { return 200 redirect$arg_b; } + location /destroyed_ctx { + js_content test.destroyed_ctx; + } + location @named { return 200 named; } @@ -87,7 +92,16 @@ $t->write_file('test.js', <<EOF); } } - export default {njs:test_njs, redirect}; + function destroyed_ctx(r) { + try { + r.return(200); + + } catch (e) { + r.internalRedirect("\@sub"); + } + } + + export default {njs:test_njs, redirect, destroyed_ctx}; EOF @@ -103,5 +117,18 @@ like(http_get('/test?unsafe=1'), qr/500 Internal Server/s, 'unsafe redirect'); like(http_get('/test?quoted=1'), qr/200 .*redirect/s, 'quoted redirect'); +get('/destroyed_ctx', 'If-Match: tt'); ############################################################################### + +sub get { + my ($url, @headers) = @_; + return http( + "GET $url HTTP/1.1" . CRLF . + 'Host: localhost' . CRLF . + 'Connection: close' . CRLF . + join(CRLF, @headers) . CRLF . CRLF + ); +} + +################################################################################ diff --git a/nginx/t/js_periodic.t b/nginx/t/js_periodic.t index d6868935..7e134588 100644 --- a/nginx/t/js_periodic.t +++ b/nginx/t/js_periodic.t @@ -56,7 +56,7 @@ http { server_name localhost; location @periodic { - js_periodic test.tick interval=30ms jitter=1ms; + js_periodic test.tick interval=20ms jitter=1ms; js_periodic test.timer interval=1s worker_affinity=all; js_periodic test.overrun interval=30ms; js_periodic test.affinity interval=50ms worker_affinity=0101; diff --git a/nginx/t/js_periodic_fetch.t b/nginx/t/js_periodic_fetch.t index a323afb8..39385132 100644 --- a/nginx/t/js_periodic_fetch.t +++ b/nginx/t/js_periodic_fetch.t @@ -99,12 +99,11 @@ $t->write_file('test.js', <<EOF); } function test_fetch(r) { - r.return(200, ngx.shared.strings.get('fetch').startsWith('okok')); + r.return(200, ngx.shared.strings.get('fetch')); } function test_multiple_fetches(r) { - r.return(200, ngx.shared.strings.get('multiple_fetches') - .startsWith('ok\@foo')); + r.return(200, ngx.shared.strings.get('multiple_fetches')); } export default { fetch, fetch_exception, multiple_fetches, test_fetch, @@ -119,8 +118,8 @@ $t->plan(3); select undef, undef, undef, 0.1; -like(http_get('/test_fetch'), qr/true/, 'periodic fetch test'); -like(http_get('/test_multiple_fetches'), qr/true/, 'multiple fetch test'); +like(http_get('/test_fetch'), qr/(ok)+/, 'periodic fetch test'); +like(http_get('/test_multiple_fetches'), qr/ok\@foo/, 'multiple fetch test'); $t->stop(); |