Skip to content

Commit

Permalink
test: make tests independently retriable (#127)
Browse files Browse the repository at this point in the history
Makes tests idempotent, so that each step can be retried indepdently. This should
make the retrying of flaky test actually work.

Fixes #124
  • Loading branch information
bcoe authored Nov 9, 2021
1 parent 412a196 commit 1f2a17b
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions media/transcoder/test/transcoder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const path = require('path');
const assert = require('assert');
const {v4: uuidv4} = require('uuid');
const {execSync} = require('child_process');
const {describe, it, before, after} = require('mocha');
const {describe, it, before, after, afterEach} = require('mocha');

const {Storage} = require('@google-cloud/storage');
const uniqueID = uuidv4().split('-')[0];
Expand Down Expand Up @@ -151,47 +151,51 @@ describe('Job template functions', () => {
});

describe('Job functions preset', () => {
before(function () {
let presetJobId;
function createJobFromPreset() {
const output = execSync(
`node createJobFromPreset.js ${projectId} ${location} ${inputUri} ${outputUriForPreset} ${preset}`,
{cwd}
);
assert.ok(
output.includes(`projects/${projectNumber}/locations/${location}/jobs/`)
);
this.presetJobId = output.toString().split('/').pop();
});
presetJobId = output.toString().split('/').pop();
}

after(function () {
afterEach(() => {
const output = execSync(
`node deleteJob.js ${projectId} ${location} ${this.presetJobId}`,
`node deleteJob.js ${projectId} ${location} ${presetJobId}`,
{cwd}
);
assert.ok(output.includes('Deleted job'));
});

it('should get a job', function () {
it('should get a job', () => {
createJobFromPreset();
const output = execSync(
`node getJob.js ${projectId} ${location} ${this.presetJobId}`,
`node getJob.js ${projectId} ${location} ${presetJobId}`,
{cwd}
);
const jobName = `projects/${projectNumber}/locations/${location}/jobs/${this.presetJobId}`;
const jobName = `projects/${projectNumber}/locations/${location}/jobs/${presetJobId}`;
assert.ok(output.includes(jobName));
});

it('should show a list of jobs', function () {
it('should show a list of jobs', () => {
createJobFromPreset();
const output = execSync(`node listJobs.js ${projectId} ${location}`, {
cwd,
});
const jobName = `projects/${projectNumber}/locations/${location}/jobs/${this.presetJobId}`;
const jobName = `projects/${projectNumber}/locations/${location}/jobs/${presetJobId}`;
assert.ok(output.includes(jobName));
});

it('should check that the job succeeded', async function () {
this.retries(5);
createJobFromPreset();
await wait(90000);
const output = execSync(
`node getJobState.js ${projectId} ${location} ${this.presetJobId}`,
`node getJobState.js ${projectId} ${location} ${presetJobId}`,
{cwd}
);
assert.ok(output.includes('Job state: SUCCEEDED'));
Expand Down

0 comments on commit 1f2a17b

Please sign in to comment.