-
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: do not re-use readstreams when retry an upload of the test repla…
…y recording (#29745) * custom async retry for any async fn * "proxied" fetch for PUT, throwing http errors * cleans up put_fetch return types & parsing * move protocol upload logic to put_protocol_artifact, rm upload_stream * changelog * changelog * manually fix wsp in snapshot * reorganizes a little, properly tests retryable logic * removes 408 as a non-retriable error in unit test * make expectation to be resolved more clear * rm unnecessary type coercion * changelog * Update cli/CHANGELOG.md * asyncRetry only throws Aggregate errors if there is more than one attempt * Update packages/server/test/unit/cloud/network/is_retryable_error_spec.ts Co-authored-by: Matt Schile <mschile@cypress.io> * Update packages/server/test/unit/cloud/network/is_retryable_error_spec.ts --------- Co-authored-by: Matt Schile <mschile@cypress.io>
- Loading branch information
1 parent
c93177b
commit 5f2236e
Showing
15 changed files
with
533 additions
and
448 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
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
2 changes: 1 addition & 1 deletion
2
packages/server/lib/cloud/api/http_error.ts → ...es/server/lib/cloud/network/http_error.ts
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,9 @@ | ||
import { NetworkError } from './network_error' | ||
import { HttpError } from './http_error' | ||
|
||
export const isRetryableError = (error?: Error) => { | ||
return error ? ( | ||
NetworkError.isNetworkError(error) || | ||
HttpError.isHttpError(error) && [408, 429, 502, 503, 504].includes(error.status) | ||
) : false | ||
} |
File renamed without changes.
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,11 @@ | ||
const ParseErrorKind = 'ParseErrorKind' | ||
|
||
export class ParseError extends Error { | ||
public readonly kind = ParseErrorKind | ||
constructor (public readonly originalError: Error, message?: string) { | ||
super(message) | ||
} | ||
static isParseError (err: Error & { kind: string }): err is ParseError { | ||
return err.kind === ParseErrorKind | ||
} | ||
} |
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,82 @@ | ||
import crossFetch from 'cross-fetch' | ||
import { NetworkError } from './network_error' | ||
import { HttpError } from './http_error' | ||
import { ParseError } from './parse_error' | ||
import { agent } from '@packages/network' | ||
import Debug from 'debug' | ||
|
||
const debug = Debug('cypress-verbose:server:cloud:api:put') | ||
|
||
type PutInit = Omit<RequestInit, 'agent' | 'method'> | ||
|
||
export const ParseKinds = Object.freeze({ | ||
JSON: 'json', | ||
TEXT: 'text', | ||
}) | ||
|
||
type ParseKind = typeof ParseKinds[keyof typeof ParseKinds] | ||
|
||
type PutOptions = PutInit & { | ||
parse?: ParseKind | ||
} | ||
|
||
export async function putFetch < | ||
TReturn extends any | ||
> (input: RequestInfo | URL, options: PutOptions = { parse: 'json' }): Promise<TReturn> { | ||
const { | ||
parse, | ||
...init | ||
} = options | ||
|
||
debug('Initiating PUT %s', input) | ||
try { | ||
const response = await crossFetch(input, { | ||
...(init || {}), | ||
method: 'PUT', | ||
// cross-fetch thinks this is in the browser, so declares | ||
// types based on that rather than on node-fetch which it | ||
// actually uses under the hood. node-fetch supports `agent`. | ||
// @ts-expect-error | ||
agent, | ||
}) | ||
|
||
if (response.status >= 400) { | ||
const err = await HttpError.fromResponse(response) | ||
|
||
throw err | ||
} | ||
|
||
try { | ||
switch (parse) { | ||
case ParseKinds.JSON: | ||
return await response.json() as TReturn | ||
case ParseKinds.TEXT: | ||
return await response.text() as TReturn | ||
default: | ||
return response.body as any | ||
} | ||
} catch (e) { | ||
const parseError = new ParseError(e, e.message) | ||
|
||
parseError.stack = e.stack | ||
throw parseError | ||
} | ||
} catch (e) { | ||
debug('Error: %O', e) | ||
if (ParseError.isParseError(e)) { | ||
throw e | ||
} else if (HttpError.isHttpError(e)) { | ||
throw e | ||
} | ||
|
||
// if the error wasn't a parsing error, it's probably a Network error | ||
const url = typeof input === 'string' ? input : | ||
input instanceof URL ? input.href : | ||
input instanceof Request ? input.url : 'UNKNOWN_URL' | ||
|
||
const networkError = new NetworkError(e, url) | ||
|
||
networkError.stack = e.stack | ||
throw networkError | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
5f2236e
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:
5f2236e
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:
5f2236e
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
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: