Skip to content

Commit 6cda9e1

Browse files
authored
feat: implementing mocha retries (#1295)
* implementing mocha retries * feat: fixing formatting for implementing mocha retries * feat: adding mocha retries to sample tests * changing # of retries * redoing # of retries * changing retry logic * changing function syntax for timeouts * changing async syntax for timeouts * changing timeout on tests * remove timeouts
1 parent e73f810 commit 6cda9e1

9 files changed

+55
-10
lines changed

samples/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"node": ">=14.0.0"
1414
},
1515
"scripts": {
16-
"test": "mocha --timeout 200000"
16+
"test": "mocha --timeout 200000",
17+
"fix": "gts fix"
1718
},
1819
"dependencies": {
1920
"@google-cloud/bigquery": "^7.3.0",
@@ -25,6 +26,7 @@
2526
"devDependencies": {
2627
"@google-cloud/datacatalog": "^4.0.0",
2728
"chai": "^4.2.0",
29+
"gts": "^5.0.0",
2830
"mocha": "^8.0.0",
2931
"proxyquire": "^2.1.3",
3032
"sinon": "^17.0.0",

samples/test/authViewTutorial.test.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
'use strict';
1616

1717
const {assert} = require('chai');
18-
const {describe, it, before, after} = require('mocha');
18+
const {describe, it, before, beforeEach, after} = require('mocha');
1919
const cp = require('child_process');
2020
const uuid = require('uuid');
2121

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

58+
beforeEach(async function () {
59+
this.currentTest.retries(2);
60+
});
61+
5862
it('should create an authorized view', async () => {
5963
const output = execSync(
6064
`node authViewTutorial.js ${projectId} ${sourceDatasetId} ${sourceTableId} ${sharedDatasetId} ${sharedViewId}`

samples/test/datasets.test.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

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

@@ -35,6 +35,10 @@ describe('Datasets', () => {
3535
await deleteDatasets();
3636
});
3737

38+
beforeEach(async function () {
39+
this.currentTest.retries(2);
40+
});
41+
3842
after(async () => {
3943
await bigquery.dataset(datasetId).delete({force: true}).catch(console.warn);
4044
});

samples/test/jobs.test.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

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

2222
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
@@ -34,6 +34,9 @@ describe('Jobs', () => {
3434
const queryOptions = {
3535
query: query,
3636
};
37+
beforeEach(async function () {
38+
this.currentTest.retries(2);
39+
});
3740

3841
const [job] = await bigquery.createQueryJob(queryOptions);
3942
jobId = job.metadata.jobReference.jobId;

samples/test/models.test.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

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

@@ -64,6 +64,10 @@ describe('Models', function () {
6464
await job.getQueryResults();
6565
});
6666

67+
beforeEach(async function () {
68+
this.currentTest.retries(2);
69+
});
70+
6771
after(async () => {
6872
await bigquery.dataset(datasetId).delete({force: true}).catch(console.warn);
6973
});
@@ -108,6 +112,10 @@ describe('Create/Delete Model', () => {
108112
await bigquery.createDataset(datasetId, datasetOptions);
109113
});
110114

115+
beforeEach(async function () {
116+
this.currentTest.retries(2);
117+
});
118+
111119
after(async () => {
112120
await bigquery.dataset(datasetId).delete({force: true}).catch(console.warn);
113121
});

samples/test/queries.test.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
'use strict';
1616

1717
const {assert} = require('chai');
18-
const {describe, it, before, after} = require('mocha');
18+
const {describe, it, before, beforeEach, after} = require('mocha');
1919
const cp = require('child_process');
2020
const uuid = require('uuid');
2121

@@ -50,6 +50,10 @@ describe('Queries', () => {
5050
projectId = tableData.metadata.tableReference.projectId;
5151
});
5252

53+
beforeEach(async function () {
54+
this.currentTest.retries(2);
55+
});
56+
5357
after(async () => {
5458
await bigquery.dataset(datasetId).delete({force: true}).catch(console.warn);
5559
});

samples/test/quickstart.test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
'use strict';
1616

1717
const {assert} = require('chai');
18-
const {describe, it, after} = require('mocha');
18+
const {describe, it, after, beforeEach} = require('mocha');
1919
const uuid = require('uuid');
2020
const cp = require('child_process');
2121
const {BigQuery} = require('@google-cloud/bigquery');
@@ -29,7 +29,9 @@ describe('Quickstart', () => {
2929
/-/gi,
3030
'_'
3131
);
32-
32+
beforeEach(async function () {
33+
this.currentTest.retries(2);
34+
});
3335
after(async () => {
3436
await bigquery.dataset(datasetName).delete({force: true});
3537
});

samples/test/routines.test.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
'use strict';
1616

1717
const {assert} = require('chai');
18-
const {describe, it, before, after} = require('mocha');
18+
const {describe, it, before, beforeEach, after} = require('mocha');
1919
const cp = require('child_process');
2020
const uuid = require('uuid');
2121

@@ -61,6 +61,10 @@ describe('Routines', () => {
6161
await routine.create(config);
6262
});
6363

64+
beforeEach(async function () {
65+
this.currentTest.retries(2);
66+
});
67+
6468
it('should create a routine', async () => {
6569
const output = execSync(
6670
`node createRoutine.js ${datasetId} ${newRoutineId}`
@@ -111,6 +115,10 @@ describe('Routines', () => {
111115
await routine.create(config);
112116
});
113117

118+
beforeEach(async function () {
119+
this.currentTest.retries(2);
120+
});
121+
114122
after(async () => {
115123
await bigquery
116124
.dataset(datasetId)

samples/test/tables.test.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ describe('Tables', () => {
9696
});
9797

9898
// to avoid getting rate limited
99-
beforeEach(done => setTimeout(done, 500));
99+
beforeEach(async function () {
100+
this.currentTest.retries(2);
101+
});
100102

101103
after(async () => {
102104
await bigquery
@@ -619,6 +621,10 @@ describe('Tables', () => {
619621
});
620622

621623
describe('Views', () => {
624+
beforeEach(async function () {
625+
this.currentTest.retries(2);
626+
});
627+
622628
it('should create a view', async () => {
623629
const output = execSync(`node createView.js ${datasetId} ${viewId}`);
624630
assert.include(output, `View ${viewId} created.`);
@@ -657,6 +663,10 @@ describe('Tables', () => {
657663
await bigquery.dataset(datasetId).createTable(tableId, tableOptions);
658664
});
659665

666+
beforeEach(async function () {
667+
this.currentTest.retries(2);
668+
});
669+
660670
after(async () => {
661671
await bigquery
662672
.dataset(datasetId)

0 commit comments

Comments
 (0)