Mercurial > hg > nginx-tests
diff 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 |
line wrap: on
line diff
--- a/stream_js.t +++ b/stream_js.t @@ -67,6 +67,7 @@ stream { js_set $js_unk js_unk; js_set $js_req_line js_req_line; js_set $js_sess_unk js_sess_unk; + js_set $js_async js_async; js_include test.js; @@ -184,6 +185,11 @@ stream { js_filter js_filter_except; proxy_pass 127.0.0.1:8090; } + + server { + listen 127.0.0.1:8100; + return $js_async; + } } EOF @@ -356,10 +362,21 @@ EOF s.on('unknown', function() {}); } + function pr(x) { + return new Promise(resolve => {resolve(x)}).then(v => v).then(v => v); + } + + async function js_async(s) { + const a1 = await pr(10); + const a2 = await pr(20); + + s.setReturnValue(`retval: \${a1 + a2}`); + } + EOF $t->run_daemon(\&stream_daemon, port(8090)); -$t->try_run('no stream njs available')->plan(22); +$t->try_run('no stream njs available')->plan(23); $t->waitforsocket('127.0.0.1:' . port(8090)); ############################################################################### @@ -392,6 +409,14 @@ stream('127.0.0.1:' . port(8097))->io('x stream('127.0.0.1:' . port(8098))->io('x'); stream('127.0.0.1:' . port(8099))->io('x'); +TODO: { +local $TODO = 'not yet' + unless get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.0'; + +is(stream('127.0.0.1:' . port(8100))->read(), 'retval: 30', 'js_async'); + +} + $t->stop(); ok(index($t->read_file('error.log'), 'SEE-THIS') > 0, 'stream js log');