Mercurial > hg > nginx-tests
comparison 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 |
comparison
equal
deleted
inserted
replaced
1737:9fc3b428b18a | 1738:9e0347f4df11 |
---|---|
65 js_set $js_var js_var; | 65 js_set $js_var js_var; |
66 js_set $js_log js_log; | 66 js_set $js_log js_log; |
67 js_set $js_unk js_unk; | 67 js_set $js_unk js_unk; |
68 js_set $js_req_line js_req_line; | 68 js_set $js_req_line js_req_line; |
69 js_set $js_sess_unk js_sess_unk; | 69 js_set $js_sess_unk js_sess_unk; |
70 js_set $js_async js_async; | |
70 | 71 |
71 js_include test.js; | 72 js_include test.js; |
72 | 73 |
73 log_format status $server_port:$status; | 74 log_format status $server_port:$status; |
74 | 75 |
181 | 182 |
182 server { | 183 server { |
183 listen 127.0.0.1:8099; | 184 listen 127.0.0.1:8099; |
184 js_filter js_filter_except; | 185 js_filter js_filter_except; |
185 proxy_pass 127.0.0.1:8090; | 186 proxy_pass 127.0.0.1:8090; |
187 } | |
188 | |
189 server { | |
190 listen 127.0.0.1:8100; | |
191 return $js_async; | |
186 } | 192 } |
187 } | 193 } |
188 | 194 |
189 EOF | 195 EOF |
190 | 196 |
354 | 360 |
355 function js_filter_except(s) { | 361 function js_filter_except(s) { |
356 s.on('unknown', function() {}); | 362 s.on('unknown', function() {}); |
357 } | 363 } |
358 | 364 |
365 function pr(x) { | |
366 return new Promise(resolve => {resolve(x)}).then(v => v).then(v => v); | |
367 } | |
368 | |
369 async function js_async(s) { | |
370 const a1 = await pr(10); | |
371 const a2 = await pr(20); | |
372 | |
373 s.setReturnValue(`retval: \${a1 + a2}`); | |
374 } | |
375 | |
359 EOF | 376 EOF |
360 | 377 |
361 $t->run_daemon(\&stream_daemon, port(8090)); | 378 $t->run_daemon(\&stream_daemon, port(8090)); |
362 $t->try_run('no stream njs available')->plan(22); | 379 $t->try_run('no stream njs available')->plan(23); |
363 $t->waitforsocket('127.0.0.1:' . port(8090)); | 380 $t->waitforsocket('127.0.0.1:' . port(8090)); |
364 | 381 |
365 ############################################################################### | 382 ############################################################################### |
366 | 383 |
367 is(stream('127.0.0.1:' . port(8080))->read(), 'addr=127.0.0.1', | 384 is(stream('127.0.0.1:' . port(8080))->read(), 'addr=127.0.0.1', |
390 | 407 |
391 stream('127.0.0.1:' . port(8097))->io('x'); | 408 stream('127.0.0.1:' . port(8097))->io('x'); |
392 stream('127.0.0.1:' . port(8098))->io('x'); | 409 stream('127.0.0.1:' . port(8098))->io('x'); |
393 stream('127.0.0.1:' . port(8099))->io('x'); | 410 stream('127.0.0.1:' . port(8099))->io('x'); |
394 | 411 |
412 TODO: { | |
413 local $TODO = 'not yet' | |
414 unless get('/njs') =~ /^([.0-9]+)$/m && $1 ge '0.7.0'; | |
415 | |
416 is(stream('127.0.0.1:' . port(8100))->read(), 'retval: 30', 'js_async'); | |
417 | |
418 } | |
419 | |
395 $t->stop(); | 420 $t->stop(); |
396 | 421 |
397 ok(index($t->read_file('error.log'), 'SEE-THIS') > 0, 'stream js log'); | 422 ok(index($t->read_file('error.log'), 'SEE-THIS') > 0, 'stream js log'); |
398 ok(index($t->read_file('error.log'), 'at fs.readFileSync') > 0, | 423 ok(index($t->read_file('error.log'), 'at fs.readFileSync') > 0, |
399 'stream js_preread backtrace'); | 424 'stream js_preread backtrace'); |