diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-21 20:56:19 +0000 |
commit | 0b6210cd37b68b94252cb798598b12974a20e1c1 (patch) | |
tree | e371686554a877842d95aa94f100bee552ff2a8e /test/connect-timeout.js | |
parent | Initial commit. (diff) | |
download | node-undici-upstream.tar.xz node-undici-upstream.zip |
Adding upstream version 5.28.2+dfsg1+~cs23.11.12.3.upstream/5.28.2+dfsg1+_cs23.11.12.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | test/connect-timeout.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/test/connect-timeout.js b/test/connect-timeout.js new file mode 100644 index 0000000..a736a54 --- /dev/null +++ b/test/connect-timeout.js @@ -0,0 +1,68 @@ +'use strict' + +const { test } = require('tap') +const { Client, Pool, errors } = require('..') +const net = require('net') +const sleep = require('atomic-sleep') + +test('priotorise socket errors over timeouts', (t) => { + t.plan(1) + const connectTimeout = 1000 + const client = new Pool('http://foobar.bar:1234', { connectTimeout: 2 }) + + client.request({ method: 'GET', path: '/foobar' }) + .then(() => t.fail()) + .catch((err) => { + t.equal(err.code, 'ENOTFOUND') + }) + + // block for 1s which is enough for the dns lookup to complete and TO to fire + sleep(connectTimeout) +}) + +// never connect +net.connect = function (options) { + return new net.Socket(options) +} + +test('connect-timeout', t => { + t.plan(1) + + const client = new Client('http://localhost:9000', { + connectTimeout: 1e3 + }) + t.teardown(client.close.bind(client)) + + const timeout = setTimeout(() => { + t.fail() + }, 2e3) + + client.request({ + path: '/', + method: 'GET' + }, (err) => { + t.type(err, errors.ConnectTimeoutError) + clearTimeout(timeout) + }) +}) + +test('connect-timeout', t => { + t.plan(1) + + const client = new Pool('http://localhost:9000', { + connectTimeout: 1e3 + }) + t.teardown(client.close.bind(client)) + + const timeout = setTimeout(() => { + t.fail() + }, 2e3) + + client.request({ + path: '/', + method: 'GET' + }, (err) => { + t.type(err, errors.ConnectTimeoutError) + clearTimeout(timeout) + }) +}) |