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

test: retry proxy_spec tests that flake #30717

Merged
merged 1 commit into from
Dec 5, 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
33 changes: 18 additions & 15 deletions packages/https-proxy/test/integration/proxy_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,29 +90,31 @@ describe('Proxy', () => {
})
})

it('closes outgoing connections when client disconnects', function () {
it('closes outgoing connections when client disconnects', async function () {
this.sandbox.spy(net, 'connect')

return request({
await request({
strictSSL: false,
url: 'https://localhost:8444/replace',
proxy: 'http://localhost:3333',
resolveWithFullResponse: true,
})
.then(() => {
// ensure the outgoing socket created for this connection was destroyed
expect(net.connect).calledOnce

const socket = net.connect.getCalls()[0].returnValue
// ensure the outgoing socket created for this connection was destroyed
expect(net.connect).calledOnce

return new Promise((resolve) => {
const socket = net.connect.getCalls()[0].returnValue

// sometimes the close event happens before we can attach the listener, causing this test to flake
if (!socket.destroyed || !socket.readyState === 'closed') {
await new Promise((resolve) => {
mschile marked this conversation as resolved.
Show resolved Hide resolved
socket.on('close', () => {
expect(socket.destroyed).to.be.true

resolve()
})
})
})
}
})

it('can boot the httpServer', () => {
Expand All @@ -127,7 +129,9 @@ describe('Proxy', () => {
})
})

context('generating certificates', () => {
context('generating certificates', function () {
this.retries(4)

it('reuses existing certificates', function () {
return request({
strictSSL: false,
Expand Down Expand Up @@ -270,13 +274,13 @@ describe('Proxy', () => {
process.env.npm_config_noproxy = 'just,some,nonsense'

process.env.NO_PROXY = ''
process.env.HTTP_PROXY = process.env.HTTPS_PROXY = 'http://localhost:9001'
process.env.HTTP_PROXY = process.env.HTTPS_PROXY = 'http://localhost:2222'

this.upstream = new DebugProxy({
keepRequests: true,
})

return this.upstream.start(9001)
return this.upstream.start(2222)
})

it('passes a request to an https server through the upstream', function () {
Expand Down Expand Up @@ -309,7 +313,7 @@ describe('Proxy', () => {
return true
}

process.env.HTTP_PROXY = (process.env.HTTPS_PROXY = 'http://foo:bar@localhost:9001')
process.env.HTTP_PROXY = process.env.HTTPS_PROXY = 'http://foo:bar@localhost:2222'

return request({
strictSSL: false,
Expand All @@ -335,10 +339,9 @@ describe('Proxy', () => {
expect(net.connect).calledOnce
const socket = net.connect.getCalls()[0].returnValue

// sometimes the close event happens before we can attach the listener,
// causing this test to flake
// sometimes the close event happens before we can attach the listener, causing this test to flake
if (!socket.destroyed || !socket.readyState === 'closed') {
return new Promise((resolve) => {
await new Promise((resolve) => {
socket.on('close', () => {
expect(socket.destroyed).to.be.true

Expand Down
Loading