Skip to content

Commit

Permalink
test: retry flaky firewall tests (#646)
Browse files Browse the repository at this point in the history
Modifies samples so they actually exit with 1 on failure. Add cleanup step and
retry logic to flaky firewall tests.

Fixes #643, #642
  • Loading branch information
bcoe authored Nov 11, 2021
1 parent 32c4160 commit 7196384
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
4 changes: 4 additions & 0 deletions compute/firewall/createFirewallRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,7 @@ function main(
}

main(...process.argv.slice(2));
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
4 changes: 4 additions & 0 deletions compute/firewall/deleteFirewallRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ function main(projectId, firewallRuleName) {
}

main(...process.argv.slice(2));
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
4 changes: 4 additions & 0 deletions compute/firewall/listFirewallRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ function main(projectId) {
}

main(...process.argv.slice(2));
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
4 changes: 4 additions & 0 deletions compute/firewall/patchFirewallPriority.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
38 changes: 35 additions & 3 deletions compute/test/samples.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]}`;

Expand All @@ -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]}`;

Expand All @@ -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]}`;

Expand Down

0 comments on commit 7196384

Please sign in to comment.