Skip to content

Commit

Permalink
chore: add graphql schema update and wrap process.kill to swallow esr…
Browse files Browse the repository at this point in the history
…ch error [run ci]
  • Loading branch information
AtofStryker committed Oct 21, 2024
1 parent e0177ff commit a22df7c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/graphql/schemas/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,7 @@ enum ErrorTypeEnum {
EXPERIMENTAL_STUDIO_REMOVED
EXPERIMENTAL_USE_DEFAULT_DOCUMENT_DOMAIN_E2E_ONLY
EXTENSION_NOT_LOADED
FIREFOX_CDP_FAILED_TO_CONNECT
FIREFOX_COULD_NOT_CONNECT
FIREFOX_GC_INTERVAL_REMOVED
FIREFOX_GECKODRIVER_FAILURE
Expand Down
26 changes: 24 additions & 2 deletions packages/server/lib/browsers/firefox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,14 +670,36 @@ export async function open (browser: Browser, url: string, options: BrowserLaunc
// now that we have the driverPID and browser PID
browserInstanceWrapper.kill = (...args) => {
// Do nothing on failure here since we're shutting down anyway

clearInstanceState({ gracefulShutdown: true })

debug('closing firefox')

const browserReturnStatus = process.kill(browserPID)
let browserReturnStatus = true

try {
browserReturnStatus = process.kill(browserPID)
} catch (e) {
if (e.code === 'ESRCH') {
debugVerbose('browser process no longer exists. continuing...')
} else {
throw e
}
}

debug('closing geckodriver and webdriver')
const driverReturnStatus = process.kill(driverPID)

let driverReturnStatus = true

try {
driverReturnStatus = process.kill(driverPID)
} catch (e) {
if (e.code === 'ESRCH') {
debugVerbose('geckodriver/webdriver process no longer exists. continuing...')
} else {
throw e
}
}

// needed for closing the browser when switching browsers in open mode to signal
// the browser is done closing
Expand Down
20 changes: 20 additions & 0 deletions packages/server/test/unit/browsers/firefox_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,26 @@ describe('lib/browsers/firefox', () => {
expect(instance.emit).to.have.been.calledWith('exit')
})

it('swallows ESRCH in kill method if thrown', async function () {
const ESRCHErr: Error & { code?: string } = new Error('BOOM')

ESRCHErr.code = 'ESRCH'
sinon.stub(process, 'kill').throws(ESRCHErr)
const instance = await firefox.open(this.browser, 'http://', this.options, this.automation)

sinon.spy(instance, 'emit')
const killResult = instance.kill()

expect(killResult).to.be.true
// kills the browser
expect(process.kill).to.have.been.calledWith(1234)
// kills the webdriver process/ geckodriver process
expect(process.kill).to.have.been.calledWith(5678)
expect(browserCriClient.close).to.have.been.called
// makes sure the exit event is called to signal to the rest of cypress server that the processes are killed
expect(instance.emit).to.have.been.calledWith('exit')
})

it('throws CDPFailedToStartFirefox if the mox:debuggerAddress capability is not returned by webdriver', function () {
delete wdInstance.capabilities['moz:debuggerAddress']
sinon.stub(process, 'kill').returns(true)
Expand Down

0 comments on commit a22df7c

Please sign in to comment.