diff --git a/compute/firewall/createFirewallRule.js b/compute/firewall/createFirewallRule.js index ca4db9bafa..33295433e0 100644 --- a/compute/firewall/createFirewallRule.js +++ b/compute/firewall/createFirewallRule.js @@ -86,3 +86,7 @@ function main( } main(...process.argv.slice(2)); +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); diff --git a/compute/firewall/deleteFirewallRule.js b/compute/firewall/deleteFirewallRule.js index 2b86dd29cf..91e3fbdd66 100644 --- a/compute/firewall/deleteFirewallRule.js +++ b/compute/firewall/deleteFirewallRule.js @@ -54,3 +54,7 @@ function main(projectId, firewallRuleName) { } main(...process.argv.slice(2)); +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); diff --git a/compute/firewall/listFirewallRules.js b/compute/firewall/listFirewallRules.js index 01c79d6fc2..ae78d10777 100644 --- a/compute/firewall/listFirewallRules.js +++ b/compute/firewall/listFirewallRules.js @@ -43,3 +43,7 @@ function main(projectId) { } main(...process.argv.slice(2)); +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); diff --git a/compute/firewall/patchFirewallPriority.js b/compute/firewall/patchFirewallPriority.js index 64d02ff011..c3c90414eb 100644 --- a/compute/firewall/patchFirewallPriority.js +++ b/compute/firewall/patchFirewallPriority.js @@ -63,3 +63,7 @@ function main(projectId, firewallRuleName, priority = 10) { } main(...process.argv.slice(2)); +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); diff --git a/compute/test/samples.test.js b/compute/test/samples.test.js index 483958c184..2aa9598c9d 100644 --- a/compute/test/samples.test.js +++ b/compute/test/samples.test.js @@ -317,7 +317,33 @@ describe('samples', () => { }); describe('firewall', () => { - it('should create and delete firewall rule', async () => { + // Clean stale firewall rules, in case prior test runs have failed. + before(async () => { + const FOUR_HOURS = 1000 * 60 * 60 * 4; + const projectId = await instancesClient.getProjectId(); + for await (const rule of firewallsClient.listAsync({ + project: projectId, + })) { + const created = new Date(rule.creationTimestamp).getTime(); + // Delete firewalls that are older than 4 hours and match our + // test prefix. + if ( + created < Date.now() - FOUR_HOURS && + rule.name.startsWith('test-firewall-rule') + ) { + console.info(`deleting stale firewall ${rule.name}`); + await firewallsClient.delete({ + project: projectId, + firewall: rule.name, + }); + } + } + }); + + it('should create and delete firewall rule', async function () { + this.retries(3); + await delay(this.test); + const projectId = await instancesClient.getProjectId(); const firewallRuleName = `test-firewall-rule-${uuid.v4().split('-')[0]}`; @@ -332,7 +358,10 @@ describe('samples', () => { assert.match(output, /Firewall rule deleted/); }); - it('should list firewall rules', async () => { + it('should list firewall rules', async function () { + this.retries(3); + await delay(this.test); + const projectId = await instancesClient.getProjectId(); const firewallRuleName = `test-firewall-rule-${uuid.v4().split('-')[0]}`; @@ -347,7 +376,10 @@ describe('samples', () => { ); }); - it('should patch firewall rule', async () => { + it('should patch firewall rule', async function () { + this.retries(3); + await delay(this.test); + const projectId = await instancesClient.getProjectId(); const firewallRuleName = `test-firewall-rule-${uuid.v4().split('-')[0]}`;