Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

fix: add backoff for test retries and get job state queries #131

Merged
merged 2 commits into from
Dec 2, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 32 additions & 6 deletions samples/test/transcoder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ const cwd = path.join(__dirname, '..');
const videoFile = `testdata/${testFileName}`;
const overlayFile = `testdata/${testOverlayFileName}`;

const delay = async (test, addMs) => {
const retries = test.currentRetry();
await new Promise(r => setTimeout(r, addMs));
// No retry on the first failure.
if (retries === 0) return;
// See: https://cloud.google.com/storage/docs/exponential-backoff
const ms = Math.pow(2, retries) * 10000 + Math.random() * 1000;
return new Promise(done => {
console.info(`retrying "${test.title}" in ${ms}ms`);
setTimeout(done, ms);
});
};

function wait(ms) {
return new Promise(resolve => {
setTimeout(() => {
Expand Down Expand Up @@ -164,6 +177,8 @@ describe('Job functions preset', () => {
}

afterEach(() => {
console.info(`delete ${presetJobId}`);

const output = execSync(
`node deleteJob.js ${projectId} ${location} ${presetJobId}`,
{cwd}
Expand Down Expand Up @@ -193,12 +208,23 @@ describe('Job functions preset', () => {
it('should check that the job succeeded', async function () {
this.retries(5);
createJobFromPreset();
await wait(90000);
const output = execSync(
`node getJobState.js ${projectId} ${location} ${presetJobId}`,
{cwd}
);
assert.ok(output.includes('Job state: SUCCEEDED'));
await delay(this.test, 30000);

let getAttempts = 0;
while (getAttempts < 5) {
const ms = Math.pow(2, getAttempts + 1) * 10000 + Math.random() * 1000;
await wait(ms);
const output = execSync(
`node getJobState.js ${projectId} ${location} ${presetJobId}`,
{cwd}
);
if (output.includes('Job state: SUCCEEDED')) {
assert.ok(true);
return;
}
getAttempts++;
}
assert.ok(false);
});
});

Expand Down