Skip to content

Commit

Permalink
implementing mocha retries
Browse files Browse the repository at this point in the history
  • Loading branch information
loferris committed Oct 23, 2023
1 parent 53781db commit 674dd37
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 11 deletions.
1 change: 1 addition & 0 deletions samples/test/auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ describe('authUserFlow()', () => {
const output = await authUserFlow.main.exchangeCode('abc123');
assert.strictEqual(output, 'tokens');
sinon.assert.calledWith(tokenStub, 'abc123');
retries(3);

Check failure on line 56 in samples/test/auth.test.js

View workflow job for this annotation

GitHub Actions / lint

'retries' is not defined
});

it('should return project id and credentials', async () => {
Expand Down
3 changes: 2 additions & 1 deletion samples/test/authViewTutorial.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ const sharedViewId = generateUuid();

const bigquery = new BigQuery();

describe('Authorized View Tutorial', () => {
describe('Authorized View Tutorial', function () {
this.retries(3);
after(async () => {
await bigquery.dataset(datasetId).delete({force: true}).catch(console.warn);
await bigquery
Expand Down
3 changes: 2 additions & 1 deletion samples/test/datasets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const datasetId = `${GCLOUD_TESTS_PREFIX}_datasets_${uuid.v4()}`.replace(

const bigquery = new BigQuery();

describe('Datasets', () => {
describe('Datasets', function () {
this.retries(3);
before(async () => {
// Delete any stale datasets from samples tests
await deleteDatasets();
Expand Down
16 changes: 16 additions & 0 deletions samples/test/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const retry = (asyncMethod: Function, counter?: number | undefined) => {

Check warning on line 1 in samples/test/helpers.ts

View workflow job for this annotation

GitHub Actions / lint

'retry' is assigned a value but never used
let retryCounter: number;

Check failure on line 2 in samples/test/helpers.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
counter ? retryCounter = counter : retryCounter = 0;

Check failure on line 3 in samples/test/helpers.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `····counter·?·retryCounter·=·counter·:·retryCounter·=·0` with `··counter·?·(retryCounter·=·counter)·:·(retryCounter·=·0)`

try {

Check failure on line 5 in samples/test/helpers.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
const res = asyncMethod;

Check failure on line 6 in samples/test/helpers.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `····`
return res;

Check failure on line 7 in samples/test/helpers.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `····`
} catch (err) {

Check failure on line 8 in samples/test/helpers.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
if (retryCounter <= 3) {

Check failure on line 9 in samples/test/helpers.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `········` with `····`
asyncMethod;

Check failure on line 10 in samples/test/helpers.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `············` with `······`
retry(asyncMethod, retryCounter++);

Check failure on line 11 in samples/test/helpers.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `······`
} else {
throw err;
}
}
}
3 changes: 2 additions & 1 deletion samples/test/jobs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
const bigquery = new BigQuery();
let jobId;

describe('Jobs', () => {
describe('Jobs', function () {
this.retries(3);
before(async () => {
const query = `SELECT name
FROM \`bigquery-public-data.usa_names.usa_1910_2013\`
Expand Down
4 changes: 3 additions & 1 deletion samples/test/models.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const GCLOUD_TESTS_PREFIX = 'nodejs_samples_tests_models';
const bigquery = new BigQuery();

describe('Models', function () {
this.retries(3);
// Increase timeout to accommodate model creation.
this.timeout(300000);
const datasetId = `${GCLOUD_TESTS_PREFIX}_${uuid.v4()}`.replace(/-/gi, '_');
Expand Down Expand Up @@ -91,7 +92,8 @@ describe('Models', function () {
});
});

describe('Create/Delete Model', () => {
describe('Create/Delete Model', function () {
this.retries(3);
const datasetId = `${GCLOUD_TESTS_PREFIX}_delete_${uuid.v4()}`.replace(
/-/gi,
'_'
Expand Down
3 changes: 2 additions & 1 deletion samples/test/queries.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ let projectId;

const bigquery = new BigQuery();

describe('Queries', () => {
describe('Queries', function () {
this.retries(3);
before(async () => {
const schema = [{name: 'age', type: 'STRING', mode: 'REQUIRED'}];
const options = {
Expand Down
3 changes: 2 additions & 1 deletion samples/test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

const bigquery = new BigQuery();

describe('Quickstart', () => {
describe('Quickstart', function () {
this.retries(3);
const datasetName = `nodejs_samples_tests_quickstart_${uuid.v4()}`.replace(
/-/gi,
'_'
Expand Down
6 changes: 4 additions & 2 deletions samples/test/routines.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const newRoutineId = generateUuid();

const bigquery = new BigQuery();

describe('Routines', () => {
describe('Routines', function () {
this.retries(3);
after(async () => {
await bigquery.dataset(datasetId).delete({force: true}).catch(console.warn);
});
Expand Down Expand Up @@ -84,7 +85,8 @@ describe('Routines', () => {
assert.include(output, 'Routine description: New description');
});

describe('Delete Routine', () => {
describe('Delete Routine', function () {
this.retries(3);
const datasetId = `gcloud_tests_${uuid.v4()}`.replace(/-/gi, '_');
const routineId = `gcloud_tests_${uuid.v4()}`.replace(/-/gi, '_');

Expand Down
9 changes: 6 additions & 3 deletions samples/test/tables.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ const partialDataFilePath = path.join(
);
const bigquery = new BigQuery();

describe('Tables', () => {
describe('Tables', function () {
this.retries(3);
before(async () => {
const [bucket] = await storage.createBucket(bucketName);
await Promise.all([
Expand Down Expand Up @@ -618,7 +619,8 @@ describe('Tables', () => {
assert.include(output, 'color: green');
});

describe('Views', () => {
describe('Views', function () {
this.retries(3);
it('should create a view', async () => {
const output = execSync(`node createView.js ${datasetId} ${viewId}`);
assert.include(output, `View ${viewId} created.`);
Expand All @@ -640,7 +642,8 @@ describe('Tables', () => {
});
});

describe('Delete Table', () => {
describe('Delete Table', function () {
this.retries(3);
const datasetId = `gcloud_tests_${uuid.v4()}`.replace(/-/gi, '_');
const tableId = `gcloud_tests_${uuid.v4()}`.replace(/-/gi, '_');

Expand Down

0 comments on commit 674dd37

Please sign in to comment.