Skip to content

Commit

Permalink
fix: in rare cases test can take longer than 180,000 timeout (#307)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored Apr 6, 2020
1 parent 39b589b commit 8c1954c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion asset/snippets/exportAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ async function main(dumpFilePath) {
// Do things with with the response.
console.log(result);
}
exportAssets();
exportAssets().catch((err) => {
throw err;
});
// [END asset_quickstart_export_assets]
}

Expand Down
18 changes: 17 additions & 1 deletion asset/snippets/test/sample.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ const storage = new Storage();
const bucketName = `asset-nodejs-${uuid.v4()}`;
const bucket = storage.bucket(bucketName);

// Some of these tests can take an extremely long time, and occasionally
// timeout, see:
// "Timeout of 180000ms exceeded. For async tests and hooks".
const delay = async test => {
const retries = test.currentRetry();
if (retries === 0) return; // no retry on the first failure.
// see: https://cloud.google.com/storage/docs/exponential-backoff:
const ms = Math.pow(2, retries) * 1000 + Math.random() * 2000;
return new Promise(done => {
console.info(`retrying "${test.title}" in ${ms}ms`);
setTimeout(done, ms);
});
};

describe('quickstart sample tests', () => {
before(async () => {
await bucket.create();
Expand All @@ -35,7 +49,9 @@ describe('quickstart sample tests', () => {
await bucket.delete();
});

it('should export assets to specified path', async () => {
it('should export assets to specified path', async function() {
this.retries(2);
await delay(this.test);
const dumpFilePath = `gs://${bucketName}/my-assets.txt`;
execSync(`node exportAssets ${dumpFilePath}`);
const file = await bucket.file('my-assets.txt');
Expand Down

0 comments on commit 8c1954c

Please sign in to comment.