From 8c1954cd0203587d2806bc44acaf43a324814099 Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Mon, 6 Apr 2020 13:05:32 -0700 Subject: [PATCH] fix: in rare cases test can take longer than 180,000 timeout (#307) --- asset/snippets/exportAssets.js | 4 +++- asset/snippets/test/sample.test.js | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/asset/snippets/exportAssets.js b/asset/snippets/exportAssets.js index 64f64a02a09..a3fcbfba736 100644 --- a/asset/snippets/exportAssets.js +++ b/asset/snippets/exportAssets.js @@ -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] } diff --git a/asset/snippets/test/sample.test.js b/asset/snippets/test/sample.test.js index 5f2cd1ccc4e..425068261bc 100644 --- a/asset/snippets/test/sample.test.js +++ b/asset/snippets/test/sample.test.js @@ -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(); @@ -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');