test: only test https-proxy socket close if socket is not already closed in client disconnect test (#28819)

This commit is contained in:
Cacie Prins
2024-02-01 15:26:25 -05:00
committed by GitHub
parent 4881a470e8
commit 4af2a29bde

View File

@@ -320,29 +320,32 @@ 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,
forever: false,
})
.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
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') {
return new Promise((resolve) => {
return socket.on('close', () => {
socket.on('close', () => {
expect(socket.destroyed).to.be.true
resolve()
})
})
})
}
})
// https://github.com/cypress-io/cypress/issues/4257