Skip to content

Commit 8c1954c

Browse files
author
Benjamin E. Coe
authored
fix: in rare cases test can take longer than 180,000 timeout (#307)
1 parent 39b589b commit 8c1954c

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

asset/snippets/exportAssets.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ async function main(dumpFilePath) {
4949
// Do things with with the response.
5050
console.log(result);
5151
}
52-
exportAssets();
52+
exportAssets().catch((err) => {
53+
throw err;
54+
});
5355
// [END asset_quickstart_export_assets]
5456
}
5557

asset/snippets/test/sample.test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ const storage = new Storage();
2626
const bucketName = `asset-nodejs-${uuid.v4()}`;
2727
const bucket = storage.bucket(bucketName);
2828

29+
// Some of these tests can take an extremely long time, and occasionally
30+
// timeout, see:
31+
// "Timeout of 180000ms exceeded. For async tests and hooks".
32+
const delay = async test => {
33+
const retries = test.currentRetry();
34+
if (retries === 0) return; // no retry on the first failure.
35+
// see: https://cloud.google.com/storage/docs/exponential-backoff:
36+
const ms = Math.pow(2, retries) * 1000 + Math.random() * 2000;
37+
return new Promise(done => {
38+
console.info(`retrying "${test.title}" in ${ms}ms`);
39+
setTimeout(done, ms);
40+
});
41+
};
42+
2943
describe('quickstart sample tests', () => {
3044
before(async () => {
3145
await bucket.create();
@@ -35,7 +49,9 @@ describe('quickstart sample tests', () => {
3549
await bucket.delete();
3650
});
3751

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

0 commit comments

Comments
 (0)