Skip to content

Commit

Permalink
Speed up e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
Will committed Oct 11, 2024
1 parent 4a34f0f commit 6949aad
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions e2e/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ import { FakeSecrets } from "./stubs/fake-secrets";

jest.setTimeout(30000);

// Speed up e2e tests by retrying failed requests with 100ms delay factor.
process.env.BACKOFF_DELAY_FACTOR = "100";

describe("e2e tests", () => {
let cloudFunctions: CloudFunctions;
let fakeGitHub: FakeGitHub;
Expand Down
7 changes: 5 additions & 2 deletions src/domain/release-archive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ describe("fetch", () => {
retries: 3,
retryDelay: expect.matchesPredicate((retryDelayFn: Function) => {
// Make sure the retry delays follow exponential backoff
// and the final retry happens after at least 1 minute total.
// Axios also randomly adds up to 20% to each delay, so test the upper bounds as well.
// and the final retry happens after at least 1 minute total
// (in this case, at least 70 seconds).
// Axios randomly adds an extra 0-20% of jitter to each delay.
// Test upper bounds as well to ensure the workflow completes reasonably quickly
// (in this case, no more than 84 seconds total).
let firstRetryDelay = retryDelayFn.call(this, 0);
let secondRetryDelay = retryDelayFn.call(this, 1);
let thirdRetryDelay = retryDelayFn.call(this, 2);
Expand Down
9 changes: 5 additions & 4 deletions src/domain/release-archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,13 @@ export class ReleaseArchive {
}
}

function tenSecondExponentialDelay(
function exponentialDelay(
retryCount: number,
error: AxiosError | undefined
): number {
const tenSeconds = 10000;
return axiosRetry.exponentialDelay(retryCount, error, tenSeconds);
// Default delay factor is 10 seconds, but can be overridden for testing.
const delayFactor = Number(process.env.BACKOFF_DELAY_FACTOR) || 10_000;
return axiosRetry.exponentialDelay(retryCount, error, delayFactor);
}

async function download(url: string, dest: string): Promise<void> {
Expand All @@ -137,7 +138,7 @@ async function download(url: string, dest: string): Promise<void> {
// gives you at least 70 seconds to upload a release archive.
axiosRetry(axios, {
retries: 3,
retryDelay: tenSecondExponentialDelay,
retryDelay: exponentialDelay,
shouldResetTimeout: true,
});

Expand Down

0 comments on commit 6949aad

Please sign in to comment.