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
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think doing this way, it will retry the whole describe section, which can be quite expensive to re run. I ran some tests here and seems like we can retry on a per spec basis.

describe('Authorized View Tutorial', () => { // Back to arrow function
  beforeEach(function(){
    console.log("this:", this.currentTest.title)
    this.currentTest.retries(2); // will try 3 times - n+1    
  })

Then I changed one of the tests to fail, to check for the retry behavior:

  it('should query stackoverflow', async () => {
    const output = execSync('node queryStackOverflow.js');
    assert.match(output, /Query Results:/);
    assert.match(output, /views/);
    assert.match(0,1)
  }); // Force failure

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);
loferris marked this conversation as resolved.
Show resolved Hide resolved
before(async () => {
// Delete any stale datasets from samples tests
await deleteDatasets();
Expand Down
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
Loading