Skip to content

Commit 1f2a17b

Browse files
authored
test: make tests independently retriable (#127)
Makes tests idempotent, so that each step can be retried indepdently. This should make the retrying of flaky test actually work. Fixes #124
1 parent 412a196 commit 1f2a17b

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

media/transcoder/test/transcoder.test.js

+16-12
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const path = require('path');
1919
const assert = require('assert');
2020
const {v4: uuidv4} = require('uuid');
2121
const {execSync} = require('child_process');
22-
const {describe, it, before, after} = require('mocha');
22+
const {describe, it, before, after, afterEach} = require('mocha');
2323

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

153153
describe('Job functions preset', () => {
154-
before(function () {
154+
let presetJobId;
155+
function createJobFromPreset() {
155156
const output = execSync(
156157
`node createJobFromPreset.js ${projectId} ${location} ${inputUri} ${outputUriForPreset} ${preset}`,
157158
{cwd}
158159
);
159160
assert.ok(
160161
output.includes(`projects/${projectNumber}/locations/${location}/jobs/`)
161162
);
162-
this.presetJobId = output.toString().split('/').pop();
163-
});
163+
presetJobId = output.toString().split('/').pop();
164+
}
164165

165-
after(function () {
166+
afterEach(() => {
166167
const output = execSync(
167-
`node deleteJob.js ${projectId} ${location} ${this.presetJobId}`,
168+
`node deleteJob.js ${projectId} ${location} ${presetJobId}`,
168169
{cwd}
169170
);
170171
assert.ok(output.includes('Deleted job'));
171172
});
172173

173-
it('should get a job', function () {
174+
it('should get a job', () => {
175+
createJobFromPreset();
174176
const output = execSync(
175-
`node getJob.js ${projectId} ${location} ${this.presetJobId}`,
177+
`node getJob.js ${projectId} ${location} ${presetJobId}`,
176178
{cwd}
177179
);
178-
const jobName = `projects/${projectNumber}/locations/${location}/jobs/${this.presetJobId}`;
180+
const jobName = `projects/${projectNumber}/locations/${location}/jobs/${presetJobId}`;
179181
assert.ok(output.includes(jobName));
180182
});
181183

182-
it('should show a list of jobs', function () {
184+
it('should show a list of jobs', () => {
185+
createJobFromPreset();
183186
const output = execSync(`node listJobs.js ${projectId} ${location}`, {
184187
cwd,
185188
});
186-
const jobName = `projects/${projectNumber}/locations/${location}/jobs/${this.presetJobId}`;
189+
const jobName = `projects/${projectNumber}/locations/${location}/jobs/${presetJobId}`;
187190
assert.ok(output.includes(jobName));
188191
});
189192

190193
it('should check that the job succeeded', async function () {
191194
this.retries(5);
195+
createJobFromPreset();
192196
await wait(90000);
193197
const output = execSync(
194-
`node getJobState.js ${projectId} ${location} ${this.presetJobId}`,
198+
`node getJobState.js ${projectId} ${location} ${presetJobId}`,
195199
{cwd}
196200
);
197201
assert.ok(output.includes('Job state: SUCCEEDED'));

0 commit comments

Comments
 (0)