# HG changeset patch # User Dmitry Volyntsev # Date 1661308805 25200 # Node ID 898598722ad4e5eda501dca9ee4f0949a41c024a # Parent 95ba1e704b7b29c39447135e18ed003ecd305924 Tests: improved stream fetch test with async callbacks. diff --git a/stream_js_fetch.t b/stream_js_fetch.t --- a/stream_js_fetch.t +++ b/stream_js_fetch.t @@ -85,14 +85,17 @@ my $p = port(8080); function preread_verify(s) { var collect = Buffer.from([]); - s.on('upstream', function (data, flags) { + s.on('upstream', async function (data, flags) { collect = Buffer.concat([collect, data]); if (collect.length >= 4 && collect.readUInt16BE(0) == 0xabcd) { s.off('upstream'); - ngx.fetch('http://127.0.0.1:$p/validate', - {body: collect.slice(2,4), headers: {Host:'aaa'}}) - .then(reply => (reply.status == 200) ? s.done(): s.deny()) + + let reply = await ngx.fetch('http://127.0.0.1:$p/validate', + {body: collect.slice(2,4), + headers: {Host:'aaa'}}); + + (reply.status == 200) ? s.done(): s.deny(); } else if (collect.length) { s.deny();