comparison stream_js_fetch.t @ 1641:6b6a496ac984

Tests: fixed stream_js_fetch.t with parallel tests. The port in njs preread_verify() should be substituted with a real port number.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 22 Jan 2021 20:02:17 +0300
parents 67adc5fd0548
children 898598722ad4
comparison
equal deleted inserted replaced
1640:67adc5fd0548 1641:6b6a496ac984
69 } 69 }
70 } 70 }
71 71
72 EOF 72 EOF
73 73
74 my $p = port(8080);
75
74 $t->write_file('test.js', <<EOF); 76 $t->write_file('test.js', <<EOF);
75 function test_njs(r) { 77 function test_njs(r) {
76 r.return(200, njs.version); 78 r.return(200, njs.version);
77 } 79 }
78 80
86 s.on('upstream', function (data, flags) { 88 s.on('upstream', function (data, flags) {
87 collect = Buffer.concat([collect, data]); 89 collect = Buffer.concat([collect, data]);
88 90
89 if (collect.length >= 4 && collect.readUInt16BE(0) == 0xabcd) { 91 if (collect.length >= 4 && collect.readUInt16BE(0) == 0xabcd) {
90 s.off('upstream'); 92 s.off('upstream');
91 ngx.fetch('http://127.0.0.1:8080/validate', 93 ngx.fetch('http://127.0.0.1:$p/validate',
92 {body: collect.slice(2,4), headers: {Host:'aaa'}}) 94 {body: collect.slice(2,4), headers: {Host:'aaa'}})
93 .then(reply => (reply.status == 200) ? s.done(): s.deny()) 95 .then(reply => (reply.status == 200) ? s.done(): s.deny())
94 96
95 } else if (collect.length) { 97 } else if (collect.length) {
96 s.deny(); 98 s.deny();