@@ -317,7 +317,33 @@ describe('samples', () => {
317317 } ) ;
318318
319319 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+
321347 const projectId = await instancesClient . getProjectId ( ) ;
322348 const firewallRuleName = `test-firewall-rule-${ uuid . v4 ( ) . split ( '-' ) [ 0 ] } ` ;
323349
@@ -332,7 +358,10 @@ describe('samples', () => {
332358 assert . match ( output , / F i r e w a l l r u l e d e l e t e d / ) ;
333359 } ) ;
334360
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+
336365 const projectId = await instancesClient . getProjectId ( ) ;
337366 const firewallRuleName = `test-firewall-rule-${ uuid . v4 ( ) . split ( '-' ) [ 0 ] } ` ;
338367
@@ -347,7 +376,10 @@ describe('samples', () => {
347376 ) ;
348377 } ) ;
349378
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+
351383 const projectId = await instancesClient . getProjectId ( ) ;
352384 const firewallRuleName = `test-firewall-rule-${ uuid . v4 ( ) . split ( '-' ) [ 0 ] } ` ;
353385
0 commit comments