From c18ad766e12d93ec1521bf7feceea5861e2a80e4 Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Mon, 28 Oct 2024 18:50:29 +0100 Subject: [PATCH] fixup: benchmark --- README.md | 3 ++- benchmarks/benchmark.js | 2 ++ test/client-connect.js | 3 ++- test/client-idempotent-body.js | 1 + test/client-upgrade.js | 3 ++- test/client.js | 6 ++++-- test/node-test/client-abort.js | 6 ++++-- test/node-test/client-connect.js | 3 ++- test/pipeline-pipelining.js | 15 ++++++++++----- test/promises.js | 2 +- 10 files changed, 30 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 40e999b3fcb..ec30c4e2420 100644 --- a/README.md +++ b/README.md @@ -402,7 +402,8 @@ Refs: https://tools.ietf.org/html/rfc7231#section-5.1.1 ### Pipelining Undici will only use pipelining if configured with a `pipelining` factor -greater than `1`. +greater than `1`. Also it is important to pass `blocking: false` to the +request options to properly pipeline requests. Undici always assumes that connections are persistent and will immediately pipeline requests, without checking whether the connection is persistent. diff --git a/benchmarks/benchmark.js b/benchmarks/benchmark.js index 7e922015225..5c8f49ea5c8 100644 --- a/benchmarks/benchmark.js +++ b/benchmarks/benchmark.js @@ -89,6 +89,8 @@ const superagentAgent = new http.Agent({ const undiciOptions = { path: '/', method: 'GET', + blocking: false, + reset: false, headersTimeout, bodyTimeout } diff --git a/test/client-connect.js b/test/client-connect.js index e002a42c571..72e575035ef 100644 --- a/test/client-connect.js +++ b/test/client-connect.js @@ -33,7 +33,8 @@ test('connect aborted after connect', async (t) => { client.connect({ path: '/', signal, - opaque: 'asd' + opaque: 'asd', + blocking: false }, (err, { opaque }) => { t.strictEqual(opaque, 'asd') t.ok(err instanceof errors.RequestAbortedError) diff --git a/test/client-idempotent-body.js b/test/client-idempotent-body.js index 07004cb8296..6f40efdd9e0 100644 --- a/test/client-idempotent-body.js +++ b/test/client-idempotent-body.js @@ -33,6 +33,7 @@ test('idempotent retry', async (t) => { path: '/', method: 'PUT', idempotent: true, + blocking: false, body }, () => { throw _err diff --git a/test/client-upgrade.js b/test/client-upgrade.js index 5cf5e553ba7..7d76f8ee148 100644 --- a/test/client-upgrade.js +++ b/test/client-upgrade.js @@ -256,7 +256,8 @@ test('upgrade wait for empty pipeline', async (t) => { client.request({ path: '/', - method: 'GET' + method: 'GET', + blocking: false }, (err) => { t.ifError(err) }) diff --git a/test/client.js b/test/client.js index 62f2c10dc7a..680ff66be10 100644 --- a/test/client.js +++ b/test/client.js @@ -1442,7 +1442,8 @@ test('increase pipelining', async (t) => { client.request({ path: '/', - method: 'GET' + method: 'GET', + blocking: false }, () => { if (!client.destroyed) { t.fail() @@ -1451,7 +1452,8 @@ test('increase pipelining', async (t) => { client.request({ path: '/', - method: 'GET' + method: 'GET', + blocking: false }, () => { if (!client.destroyed) { t.fail() diff --git a/test/node-test/client-abort.js b/test/node-test/client-abort.js index a5337f16ae2..52395f0dbfb 100644 --- a/test/node-test/client-abort.js +++ b/test/node-test/client-abort.js @@ -126,7 +126,8 @@ test('abort pipelined', async (t) => { let counter = 0 client.dispatch({ method: 'GET', - path: '/' + path: '/', + blocking: false }, { onConnect (abort) { // This request will be retried @@ -151,7 +152,8 @@ test('abort pipelined', async (t) => { client.dispatch({ method: 'GET', - path: '/' + path: '/', + blocking: false }, { onConnect (abort) { abort() diff --git a/test/node-test/client-connect.js b/test/node-test/client-connect.js index 0bf65488d81..28271d348cf 100644 --- a/test/node-test/client-connect.js +++ b/test/node-test/client-connect.js @@ -142,7 +142,8 @@ test('connect wait for empty pipeline', async (t) => { client.request({ path: '/', - method: 'GET' + method: 'GET', + blocking: false }, (err) => { p.ifError(err) }) diff --git a/test/pipeline-pipelining.js b/test/pipeline-pipelining.js index b244925786a..27ea1bb21ed 100644 --- a/test/pipeline-pipelining.js +++ b/test/pipeline-pipelining.js @@ -26,7 +26,8 @@ test('pipeline pipelining', async (t) => { t.equal(client[kRunning], 0) client.pipeline({ method: 'GET', - path: '/' + path: '/', + blocking: false }, ({ body }) => body).end().resume() t.equal(client[kBusy], true) t.deepStrictEqual(client[kRunning], 0) @@ -34,7 +35,8 @@ test('pipeline pipelining', async (t) => { client.pipeline({ method: 'GET', - path: '/' + path: '/', + blocking: false }, ({ body }) => body).end().resume() t.equal(client[kBusy], true) t.deepStrictEqual(client[kRunning], 0) @@ -74,7 +76,8 @@ test('pipeline pipelining retry', async (t) => { client[kConnect](() => { client.pipeline({ method: 'GET', - path: '/' + path: '/', + blocking: false }, ({ body }) => body).end().resume() .on('error', (err) => { t.ok(err) @@ -85,7 +88,8 @@ test('pipeline pipelining retry', async (t) => { client.pipeline({ method: 'GET', - path: '/' + path: '/', + blocking: false }, ({ body }) => body).end().resume() t.equal(client[kBusy], true) t.deepStrictEqual(client[kRunning], 0) @@ -93,7 +97,8 @@ test('pipeline pipelining retry', async (t) => { client.pipeline({ method: 'GET', - path: '/' + path: '/', + blocking: false }, ({ body }) => body).end().resume() t.equal(client[kBusy], true) t.deepStrictEqual(client[kRunning], 0) diff --git a/test/promises.js b/test/promises.js index 5d47adc3640..1eddfc216f6 100644 --- a/test/promises.js +++ b/test/promises.js @@ -245,7 +245,7 @@ test('20 times GET with pipelining 10, async await support', async (t) => { async function makeRequestAndExpectUrl (client, i, t) { try { - const { statusCode, body } = await client.request({ path: '/' + i, method: 'GET' }) + const { statusCode, body } = await client.request({ path: '/' + i, method: 'GET', blocking: false }) t.strictEqual(statusCode, 200) const bufs = [] body.on('data', (buf) => {