@@ -42,16 +42,9 @@ let vm;
42
42
// Some of these tests can take an extremely long time, and occasionally
43
43
// timeout, see:
44
44
// "Timeout of 180000ms exceeded. For async tests and hooks".
45
- const delay = async test => {
46
- const retries = test . currentRetry ( ) ;
47
- if ( retries === 0 ) return ; // no retry on the first failure.
48
- // see: https://cloud.google.com/storage/docs/exponential-backoff:
49
- const ms = Math . pow ( 2 , retries ) * 1000 + Math . random ( ) * 2000 ;
50
- return new Promise ( done => {
51
- console . info ( `retrying "${ test . title } " in ${ ms } ms` ) ;
52
- setTimeout ( done , ms ) ;
53
- } ) ;
54
- } ;
45
+ function sleep ( ms ) {
46
+ return new Promise ( resolve => setTimeout ( resolve , ms ) ) ;
47
+ }
55
48
56
49
describe ( 'quickstart sample tests' , ( ) => {
57
50
before ( async ( ) => {
@@ -67,13 +60,17 @@ describe('quickstart sample tests', () => {
67
60
await vm . delete ( ) ;
68
61
} ) ;
69
62
70
- it ( 'should export assets to specified path' , async function ( ) {
71
- this . retries ( 2 ) ;
72
- await delay ( this . test ) ;
63
+ it ( 'should export assets to specified path' , async ( ) => {
73
64
const dumpFilePath = `gs://${ bucketName } /my-assets.txt` ;
74
65
execSync ( `node exportAssets ${ dumpFilePath } ` ) ;
75
- const file = await bucket . file ( 'my-assets.txt' ) ;
76
- const exists = await file . exists ( ) ;
66
+ let waitMs = 1000 ;
67
+ let exists = false ;
68
+ let file ;
69
+ for ( let retry = 0 ; retry < 3 && ! exists ; ++ retry ) {
70
+ await sleep ( ( waitMs *= 2 ) ) ;
71
+ file = await bucket . file ( 'my-assets.txt' ) ;
72
+ exists = await file . exists ( ) ;
73
+ }
77
74
assert . ok ( exists ) ;
78
75
await file . delete ( ) ;
79
76
} ) ;
@@ -115,33 +112,49 @@ describe('quickstart sample tests', () => {
115
112
assert . include ( stdout , '//cloudresourcemanager.googleapis.com/projects' ) ;
116
113
} ) ;
117
114
118
- it ( 'should analyze iam policy and write analysis results to gcs successfully' , async function ( ) {
119
- this . retries ( 2 ) ;
120
- await delay ( this . test ) ;
115
+ it ( 'should analyze iam policy and write analysis results to gcs successfully' , async ( ) => {
121
116
const uri = `gs://${ bucketName } /my-analysis.json` ;
122
117
execSync ( `node analyzeIamPolicyLongrunningGcs ${ uri } ` ) ;
123
- const file = await bucket . file ( 'my-analysis.json' ) ;
124
- const exists = await file . exists ( ) ;
118
+ let waitMs = 1000 ;
119
+ let exists = false ;
120
+ let file ;
121
+ for ( let retry = 0 ; retry < 3 && ! exists ; ++ retry ) {
122
+ await sleep ( ( waitMs *= 2 ) ) ;
123
+ file = await bucket . file ( 'my-analysis.json' ) ;
124
+ exists = await file . exists ( ) ;
125
+ }
125
126
assert . ok ( exists ) ;
126
127
await file . delete ( ) ;
127
128
} ) ;
128
129
129
- it ( 'should analyze iam policy and write analysis results to bigquery successfully' , async function ( ) {
130
- this . retries ( 2 ) ;
131
- await delay ( this . test ) ;
130
+ it ( 'should analyze iam policy and write analysis results to bigquery successfully' , async ( ) => {
132
131
const tablePrefix = 'analysis_nodejs' ;
133
132
execSync (
134
133
`node analyzeIamPolicyLongrunningBigquery ${ datasetId } ${ tablePrefix } `
135
134
) ;
136
- const metadataTable = await bigquery
137
- . dataset ( datasetId )
138
- . table ( 'analysis_nodejs_analysis' ) ;
139
- const metadataTable_exists = await metadataTable . exists ( ) ;
135
+ let waitMs = 1000 ;
136
+ let metadataTable ;
137
+ let metadataTable_exists = false ;
138
+ let resultsTable ;
139
+ let resultsTable_exists = false ;
140
+
141
+ for (
142
+ let retry = 0 ;
143
+ retry < 3 && ! ( metadataTable_exists || resultsTable_exists ) ;
144
+ ++ retry
145
+ ) {
146
+ await sleep ( ( waitMs *= 2 ) ) ;
147
+ metadataTable = await bigquery
148
+ . dataset ( datasetId )
149
+ . table ( 'analysis_nodejs_analysis' ) ;
150
+ metadataTable_exists = await metadataTable . exists ( ) ;
151
+ resultsTable = await bigquery
152
+ . dataset ( datasetId )
153
+ . table ( 'analysis_nodejs_analysis_result' ) ;
154
+ resultsTable_exists = await resultsTable . exists ( ) ;
155
+ }
156
+
140
157
assert . ok ( metadataTable_exists ) ;
141
- const resultsTable = await bigquery
142
- . dataset ( datasetId )
143
- . table ( 'analysis_nodejs_analysis_result' ) ;
144
- const resultsTable_exists = await resultsTable . exists ( ) ;
145
158
assert . ok ( resultsTable_exists ) ;
146
159
await metadataTable . delete ( ) ;
147
160
await resultsTable . delete ( ) ;
0 commit comments