Skip to content

Commit

Permalink
fix: attempt reconnection if CDP websocket in closed/closing state (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig authored Jul 16, 2020
1 parent 582fb15 commit aae5187
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/server/lib/browsers/cri-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const debugVerboseSend = debugModule('cypress-verbose:server:browsers:cri-client
// debug using cypress-verbose:server:browsers:cri-client:recv:*
const debugVerboseReceive = debugModule('cypress-verbose:server:browsers:cri-client:recv:[<--]')

const WEBSOCKET_NOT_OPEN_RE = /^WebSocket is not open/
const WEBSOCKET_NOT_OPEN_RE = /^WebSocket is (?:not open|already in CLOSING or CLOSED state)/

/**
* Url returned by the Chrome Remote Interface
Expand Down
44 changes: 39 additions & 5 deletions packages/server/test/unit/browsers/cri-client_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ describe('lib/browsers/cri-client', function () {
let send: sinon.SinonStub
let criImport: sinon.SinonStub
let onError: sinon.SinonStub

function getClient () {
return criClient.create(DEBUGGER_URL, onError)
}
let getClient: () => ReturnType<typeof create>

beforeEach(function () {
sinon.stub(Bluebird, 'promisify').returnsArg(0)
Expand All @@ -29,11 +26,17 @@ describe('lib/browsers/cri-client', function () {
target: DEBUGGER_URL,
local: true,
})
.resolves({ send, _notifier: new EventEmitter() })
.resolves({
send,
close: sinon.stub(),
_notifier: new EventEmitter(),
})

criClient = proxyquire('../lib/browsers/cri-client', {
'chrome-remote-interface': criImport,
})

getClient = () => criClient.create(DEBUGGER_URL, onError)
})

context('.create', function () {
Expand All @@ -51,6 +54,37 @@ describe('lib/browsers/cri-client', function () {
client.send('Browser.getVersion', { baz: 'quux' })
expect(send).to.be.calledWith('Browser.getVersion', { baz: 'quux' })
})

it('rejects if cri.send rejects', async function () {
const err = new Error

send.rejects(err)
const client = await getClient()

await expect(client.send('Browser.getVersion', { baz: 'quux' }))
.to.be.rejectedWith(err)
})

context('retries', () => {
([
'WebSocket is not open',
// @see https://github.com/cypress-io/cypress/issues/7180
'WebSocket is already in CLOSING or CLOSED state',
]).forEach((msg) => {
it(`with '${msg}'`, async function () {
const err = new Error(msg)

send.onFirstCall().rejects(err)
send.onSecondCall().resolves()

const client = await getClient()

await client.send('Browser.getVersion', { baz: 'quux' })

expect(send).to.be.calledTwice
})
})
})
})

context('#ensureMinimumProtocolVersion', function () {
Expand Down

4 comments on commit aae5187

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on aae5187 Jul 16, 2020

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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.10.1/linux-x64/circle-develop-aae5187f6be280092a786e54496b328df1d7f9d5-397678/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.10.1/circle-develop-aae5187f6be280092a786e54496b328df1d7f9d5-397658/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on aae5187 Jul 16, 2020

Choose a reason for hiding this comment

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

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

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.10.1/win32-x64/appveyor-develop-aae5187f6be280092a786e54496b328df1d7f9d5-34144783/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.10.1/appveyor-develop-aae5187f6be280092a786e54496b328df1d7f9d5-34144783/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/4.10.1/win32-x64/appveyor-develop-aae5187f6be280092a786e54496b328df1d7f9d5-34144783/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.10.1/appveyor-develop-aae5187f6be280092a786e54496b328df1d7f9d5-34144783/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.10.1/win32-x64/appveyor-develop-aae5187f6be280092a786e54496b328df1d7f9d5-34144783/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.10.1/appveyor-develop-aae5187f6be280092a786e54496b328df1d7f9d5-34144783/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.10.1/win32-x64/appveyor-develop-aae5187f6be280092a786e54496b328df1d7f9d5-34144783/cypress.zip npm install https://cdn.cypress.io/beta/npm/4.10.1/appveyor-develop-aae5187f6be280092a786e54496b328df1d7f9d5-34144783/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on aae5187 Jul 16, 2020

Choose a reason for hiding this comment

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

AppVeyor has built the win32 ia32 version of the Test Runner.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

Instructions are included below, depending on the shell you are using.

In Command Prompt (cmd.exe):

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.10.1/win32-ia32/appveyor-develop-aae5187f6be280092a786e54496b328df1d7f9d5-34144783/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.10.1/appveyor-develop-aae5187f6be280092a786e54496b328df1d7f9d5-34144783/cypress.tgz

In PowerShell:

$env:CYPRESS_INSTALL_BINARY = https://cdn.cypress.io/beta/binary/4.10.1/win32-ia32/appveyor-develop-aae5187f6be280092a786e54496b328df1d7f9d5-34144783/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.10.1/appveyor-develop-aae5187f6be280092a786e54496b328df1d7f9d5-34144783/cypress.tgz

In Git Bash:

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.10.1/win32-ia32/appveyor-develop-aae5187f6be280092a786e54496b328df1d7f9d5-34144783/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.10.1/appveyor-develop-aae5187f6be280092a786e54496b328df1d7f9d5-34144783/cypress.tgz

Using cross-env:

If the above commands do not work for you, you can also try using cross-env:

npm i -g cross-env
cross-env CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.10.1/win32-ia32/appveyor-develop-aae5187f6be280092a786e54496b328df1d7f9d5-34144783/cypress.zip npm install https://cdn.cypress.io/beta/npm/4.10.1/appveyor-develop-aae5187f6be280092a786e54496b328df1d7f9d5-34144783/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on aae5187 Jul 16, 2020

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.

You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/4.10.1/darwin-x64/circle-develop-aae5187f6be280092a786e54496b328df1d7f9d5-397687/cypress.zip
npm install https://cdn.cypress.io/beta/npm/4.10.1/circle-develop-aae5187f6be280092a786e54496b328df1d7f9d5-397683/cypress.tgz

Please sign in to comment.