-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Unhandled "WebSocket connection closed" when CDP connection is u…
…nstable (#29830) * unit and integration tests that reproduce websocket disconnected unhandled exception * WIP: command queue * complete command queue and retry refactor * cri-client changes pass tests; modify certain tests for readability and accuracy * removes unnecessary logic from command queue, adds unit tests for command queue * rm unused cdp state - this should be reserved for future refactor * small edits to cri-client: better error handling, more comprehensive comments * comment re: queue property * rearrange cri client member methods for readability * further edits * Changelog * Update cli/CHANGELOG.md Co-authored-by: Mike McCready <66998419+MikeMcC399@users.noreply.github.com> * fix continuous retry on close * split heavier debugs to verbose --------- Co-authored-by: Mike McCready <66998419+MikeMcC399@users.noreply.github.com> Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
- Loading branch information
1 parent
cbbc8ee
commit 8a48ee7
Showing
6 changed files
with
699 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import type ProtocolMapping from 'devtools-protocol/types/protocol-mapping' | ||
import pDefer, { DeferredPromise } from 'p-defer' | ||
import type { CdpCommand } from './cdp_automation' | ||
import Debug from 'debug' | ||
|
||
const debug = Debug('cypress:server:browsers:cdp-command-queue') | ||
const debugVerbose = Debug('cypress:server:browsers:cd-command-queue') | ||
|
||
type CommandReturn<T extends CdpCommand> = ProtocolMapping.Commands[T]['returnType'] | ||
|
||
export type Command<T extends CdpCommand> = { | ||
command: T | ||
params?: object | ||
deferred: DeferredPromise<CommandReturn<T>> | ||
sessionId?: string | ||
} | ||
|
||
export class CDPCommandQueue { | ||
private queue: Command<any>[] = [] | ||
|
||
public get entries () { | ||
return [...this.queue] | ||
} | ||
|
||
public add <TCmd extends CdpCommand> ( | ||
command: TCmd, | ||
params: ProtocolMapping.Commands[TCmd]['paramsType'][0], | ||
sessionId?: string, | ||
): Promise<CommandReturn<TCmd>> { | ||
debug('enqueing command %s', command) | ||
debugVerbose('enqueing command %s with params %o', command, params) | ||
|
||
const deferred = pDefer<CommandReturn<TCmd>>() | ||
|
||
const commandPackage: Command<TCmd> = { | ||
command, | ||
params, | ||
deferred, | ||
sessionId, | ||
} | ||
|
||
this.queue.push(commandPackage) | ||
|
||
debug('Command enqueued; new length: %d', this.queue.length) | ||
debugVerbose('Queue Contents: %O', this.queue) | ||
|
||
return deferred.promise | ||
} | ||
|
||
public clear () { | ||
debug('clearing command queue') | ||
this.queue = [] | ||
} | ||
|
||
public extract<T extends CdpCommand> (search: Partial<Command<T>>): Command<T> | undefined { | ||
// this should find, remove, and return if found a given command | ||
|
||
const index = this.queue.findIndex((enqueued) => { | ||
for (let k of Object.keys(search)) { | ||
if (search[k] !== enqueued[k]) { | ||
return false | ||
} | ||
} | ||
|
||
return true | ||
}) | ||
|
||
debug('extracting %o from commands at index %d', search, index) | ||
|
||
if (index === -1) { | ||
return undefined | ||
} | ||
|
||
const [extracted] = this.queue.splice(index, 1) | ||
|
||
return extracted | ||
} | ||
|
||
public shift () { | ||
return this.queue.shift() | ||
} | ||
|
||
public unshift (value: Command<any>) { | ||
return this.queue.unshift(value) | ||
} | ||
} |
Oops, something went wrong.
8a48ee7
There was a problem hiding this comment.
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:
8a48ee7
There was a problem hiding this comment.
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:
8a48ee7
There was a problem hiding this comment.
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:
8a48ee7
There was a problem hiding this comment.
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: