From 1f2a17b3866fc0a6c83a4beebb65c2769a564840 Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Tue, 9 Nov 2021 14:52:26 -0500 Subject: [PATCH] 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 --- media/transcoder/test/transcoder.test.js | 28 ++++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/media/transcoder/test/transcoder.test.js b/media/transcoder/test/transcoder.test.js index 4a780209c3..d1f6a0470c 100644 --- a/media/transcoder/test/transcoder.test.js +++ b/media/transcoder/test/transcoder.test.js @@ -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]; @@ -151,7 +151,8 @@ 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} @@ -159,39 +160,42 @@ describe('Job functions preset', () => { 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'));