Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implementing mocha retries #1295

Merged
merged 13 commits into from
Nov 2, 2023
4 changes: 3 additions & 1 deletion samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"node": ">=14.0.0"
},
"scripts": {
"test": "mocha --timeout 200000"
"test": "mocha --timeout 200000",
"fix": "gts fix"
},
"dependencies": {
"@google-cloud/bigquery": "^7.3.0",
Expand All @@ -25,6 +26,7 @@
"devDependencies": {
"@google-cloud/datacatalog": "^4.0.0",
"chai": "^4.2.0",
"gts": "^5.0.0",
"mocha": "^8.0.0",
"proxyquire": "^2.1.3",
"sinon": "^17.0.0",
Expand Down
6 changes: 5 additions & 1 deletion samples/test/authViewTutorial.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'use strict';

const {assert} = require('chai');
const {describe, it, before, after} = require('mocha');
const {describe, it, before, beforeEach, after} = require('mocha');
const cp = require('child_process');
const uuid = require('uuid');

Expand Down Expand Up @@ -55,6 +55,10 @@ describe('Authorized View Tutorial', () => {
projectId = tableData.metadata.tableReference.projectId;
});

beforeEach(async function () {
this.currentTest.retries(2);
});

it('should create an authorized view', async () => {
const output = execSync(
`node authViewTutorial.js ${projectId} ${sourceDatasetId} ${sourceTableId} ${sharedDatasetId} ${sharedViewId}`
Expand Down
6 changes: 5 additions & 1 deletion samples/test/datasets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

const {BigQuery} = require('@google-cloud/bigquery');
const {assert} = require('chai');
const {describe, it, after, before} = require('mocha');
const {describe, it, after, before, beforeEach} = require('mocha');
const cp = require('child_process');
const uuid = require('uuid');

Expand All @@ -35,6 +35,10 @@ describe('Datasets', () => {
await deleteDatasets();
});

beforeEach(async function () {
this.currentTest.retries(2);
});

after(async () => {
await bigquery.dataset(datasetId).delete({force: true}).catch(console.warn);
});
Expand Down
5 changes: 4 additions & 1 deletion samples/test/jobs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

const {BigQuery} = require('@google-cloud/bigquery');
const {assert} = require('chai');
const {describe, it, before} = require('mocha');
const {describe, it, before, beforeEach} = require('mocha');
const cp = require('child_process');

const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
Expand All @@ -34,6 +34,9 @@ describe('Jobs', () => {
const queryOptions = {
query: query,
};
beforeEach(async function () {
this.currentTest.retries(2);
});

const [job] = await bigquery.createQueryJob(queryOptions);
jobId = job.metadata.jobReference.jobId;
Expand Down
10 changes: 9 additions & 1 deletion samples/test/models.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

const {BigQuery} = require('@google-cloud/bigquery');
const {assert} = require('chai');
const {describe, it, before, after} = require('mocha');
const {describe, it, before, beforeEach, after} = require('mocha');
const cp = require('child_process');
const uuid = require('uuid');

Expand Down Expand Up @@ -64,6 +64,10 @@ describe('Models', function () {
await job.getQueryResults();
});

beforeEach(async function () {
this.currentTest.retries(2);
});

after(async () => {
await bigquery.dataset(datasetId).delete({force: true}).catch(console.warn);
});
Expand Down Expand Up @@ -108,6 +112,10 @@ describe('Create/Delete Model', () => {
await bigquery.createDataset(datasetId, datasetOptions);
});

beforeEach(async function () {
this.currentTest.retries(2);
});

after(async () => {
await bigquery.dataset(datasetId).delete({force: true}).catch(console.warn);
});
Expand Down
6 changes: 5 additions & 1 deletion samples/test/queries.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'use strict';

const {assert} = require('chai');
const {describe, it, before, after} = require('mocha');
const {describe, it, before, beforeEach, after} = require('mocha');
const cp = require('child_process');
const uuid = require('uuid');

Expand Down Expand Up @@ -50,6 +50,10 @@ describe('Queries', () => {
projectId = tableData.metadata.tableReference.projectId;
});

beforeEach(async function () {
this.currentTest.retries(2);
});

after(async () => {
await bigquery.dataset(datasetId).delete({force: true}).catch(console.warn);
});
Expand Down
6 changes: 4 additions & 2 deletions samples/test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'use strict';

const {assert} = require('chai');
const {describe, it, after} = require('mocha');
const {describe, it, after, beforeEach} = require('mocha');
const uuid = require('uuid');
const cp = require('child_process');
const {BigQuery} = require('@google-cloud/bigquery');
Expand All @@ -29,7 +29,9 @@ describe('Quickstart', () => {
/-/gi,
'_'
);

beforeEach(async function () {
this.currentTest.retries(2);
});
after(async () => {
await bigquery.dataset(datasetName).delete({force: true});
});
Expand Down
10 changes: 9 additions & 1 deletion samples/test/routines.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
'use strict';

const {assert} = require('chai');
const {describe, it, before, after} = require('mocha');
const {describe, it, before, beforeEach, after} = require('mocha');
const cp = require('child_process');
const uuid = require('uuid');

Expand Down Expand Up @@ -61,6 +61,10 @@ describe('Routines', () => {
await routine.create(config);
});

beforeEach(async function () {
this.currentTest.retries(2);
});

it('should create a routine', async () => {
const output = execSync(
`node createRoutine.js ${datasetId} ${newRoutineId}`
Expand Down Expand Up @@ -111,6 +115,10 @@ describe('Routines', () => {
await routine.create(config);
});

beforeEach(async function () {
this.currentTest.retries(2);
});

after(async () => {
await bigquery
.dataset(datasetId)
Expand Down
12 changes: 11 additions & 1 deletion samples/test/tables.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ describe('Tables', () => {
});

// to avoid getting rate limited
beforeEach(done => setTimeout(done, 500));
beforeEach(async function () {
this.currentTest.retries(2);
});

after(async () => {
await bigquery
Expand Down Expand Up @@ -619,6 +621,10 @@ describe('Tables', () => {
});

describe('Views', () => {
beforeEach(async function () {
this.currentTest.retries(2);
});

it('should create a view', async () => {
const output = execSync(`node createView.js ${datasetId} ${viewId}`);
assert.include(output, `View ${viewId} created.`);
Expand Down Expand Up @@ -657,6 +663,10 @@ describe('Tables', () => {
await bigquery.dataset(datasetId).createTable(tableId, tableOptions);
});

beforeEach(async function () {
this.currentTest.retries(2);
});

after(async () => {
await bigquery
.dataset(datasetId)
Expand Down
Loading