@@ -317,7 +317,33 @@ describe('samples', () => {
317
317
} ) ;
318
318
319
319
describe ( 'firewall' , ( ) => {
320
- it ( 'should create and delete firewall rule' , async ( ) => {
320
+ // Clean stale firewall rules, in case prior test runs have failed.
321
+ before ( async ( ) => {
322
+ const FOUR_HOURS = 1000 * 60 * 60 * 4 ;
323
+ const projectId = await instancesClient . getProjectId ( ) ;
324
+ for await ( const rule of firewallsClient . listAsync ( {
325
+ project : projectId ,
326
+ } ) ) {
327
+ const created = new Date ( rule . creationTimestamp ) . getTime ( ) ;
328
+ // Delete firewalls that are older than 4 hours and match our
329
+ // test prefix.
330
+ if (
331
+ created < Date . now ( ) - FOUR_HOURS &&
332
+ rule . name . startsWith ( 'test-firewall-rule' )
333
+ ) {
334
+ console . info ( `deleting stale firewall ${ rule . name } ` ) ;
335
+ await firewallsClient . delete ( {
336
+ project : projectId ,
337
+ firewall : rule . name ,
338
+ } ) ;
339
+ }
340
+ }
341
+ } ) ;
342
+
343
+ it ( 'should create and delete firewall rule' , async function ( ) {
344
+ this . retries ( 3 ) ;
345
+ await delay ( this . test ) ;
346
+
321
347
const projectId = await instancesClient . getProjectId ( ) ;
322
348
const firewallRuleName = `test-firewall-rule-${ uuid . v4 ( ) . split ( '-' ) [ 0 ] } ` ;
323
349
@@ -332,7 +358,10 @@ describe('samples', () => {
332
358
assert . match ( output , / F i r e w a l l r u l e d e l e t e d / ) ;
333
359
} ) ;
334
360
335
- it ( 'should list firewall rules' , async ( ) => {
361
+ it ( 'should list firewall rules' , async function ( ) {
362
+ this . retries ( 3 ) ;
363
+ await delay ( this . test ) ;
364
+
336
365
const projectId = await instancesClient . getProjectId ( ) ;
337
366
const firewallRuleName = `test-firewall-rule-${ uuid . v4 ( ) . split ( '-' ) [ 0 ] } ` ;
338
367
@@ -347,7 +376,10 @@ describe('samples', () => {
347
376
) ;
348
377
} ) ;
349
378
350
- it ( 'should patch firewall rule' , async ( ) => {
379
+ it ( 'should patch firewall rule' , async function ( ) {
380
+ this . retries ( 3 ) ;
381
+ await delay ( this . test ) ;
382
+
351
383
const projectId = await instancesClient . getProjectId ( ) ;
352
384
const firewallRuleName = `test-firewall-rule-${ uuid . v4 ( ) . split ( '-' ) [ 0 ] } ` ;
353
385
0 commit comments