Skip to content

Commit

Permalink
test: fix proxy spec flake (#30717)
Browse files Browse the repository at this point in the history
  • Loading branch information
mschile authored Dec 5, 2024
1 parent 241088a commit 02db483
Showing 1 changed file with 18 additions and 15 deletions.
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) => {
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

5 comments on commit 02db483

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 02db483 Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.16.2/linux-x64/develop-02db483962ee20a6c2bc02a0243168c9255f6e6e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 02db483 Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.16.2/linux-arm64/develop-02db483962ee20a6c2bc02a0243168c9255f6e6e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 02db483 Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.16.2/win32-x64/develop-02db483962ee20a6c2bc02a0243168c9255f6e6e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 02db483 Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.16.2/darwin-arm64/develop-02db483962ee20a6c2bc02a0243168c9255f6e6e/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 02db483 Dec 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.16.2/darwin-x64/develop-02db483962ee20a6c2bc02a0243168c9255f6e6e/cypress.tgz

Please sign in to comment.