Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: deflake connect-timeout test #2851

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions test/connect-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@ const { test, after, describe } = require('node:test')
const { Client, Pool, errors } = require('..')
const net = require('node:net')
const assert = require('node:assert')
const sleep = ms => Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, Number(ms))

// Using describe instead of test to avoid the timeout
describe('prioritize socket errors over timeouts', () => {
describe('prioritize socket errors over timeouts', async () => {
const t = tspl({ ...assert, after: () => {} }, { plan: 1 })
const connectTimeout = 1000
const client = new Pool('http://foobar.bar:1234', { connectTimeout: 2 })
const client = new Pool('http://foobar.bar:1234', { connectTimeout: 1 })

client.request({ method: 'GET', path: '/foobar' })
.then(() => t.fail())
.catch((err) => {
t.strictEqual(['ENOTFOUND', 'EAI_AGAIN'].includes(err.code), true)
t.strictEqual(err.code !== 'UND_ERR_CONNECT_TIMEOUT', true)
})

// block for 1s which is enough for the dns lookup to complete and TO to fire
sleep(connectTimeout)
// block for 1s which is enough for the dns lookup to complete and the
// Timeout to fire
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, Number(1000))

await t.completed
})

// never connect
// mock net.connect to avoid the dns lookup
net.connect = function (options) {
return new net.Socket(options)
}
Expand Down
Loading