Skip to content

Commit

Permalink
chore(system-test): add retry and delay for flaky test (#730)
Browse files Browse the repository at this point in the history
* chore(system-test): add retry and delay for flaky test
  • Loading branch information
FrodoTheTrue authored May 19, 2022
1 parent a419a0c commit 21daed5
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions packages/google-cloud-compute/system-test/compute.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,25 @@ const compute = require('../');

const DiskType = compute.protos.google.cloud.compute.v1.AttachedDisk.Type;

const delay = async test => {
const retries = test.currentRetry();
if (retries === 0) return; // no retry on the first failure.
// see: https://github.com/grpc/proposal/blob/master/A6-client-retries.md#exponential-backoff
const ms = Math.pow(2, retries) * 500 + Math.random() * 1000;
return new Promise(done => {
console.info(`retrying "${test.title}" in ${ms}ms`);
setTimeout(done, ms);
});
};

describe('Compute', () => {
const region = 'us-central1';
const zone = 'us-central1-a';
let client = null;
let project = null;
let dirty = false;
let operationsClient = null;
let instancesClient = null;

before(async () => {
operationsClient = new compute.ZoneOperationsClient({fallback: 'rest'});
Expand Down Expand Up @@ -143,6 +155,27 @@ describe('Compute', () => {

before(async () => {
client = new compute.FirewallsClient({fallback: 'rest'});
instancesClient = new compute.InstancesClient({fallback: 'rest'});

const FOUR_HOURS = 1000 * 60 * 60 * 4;
const projectId = await instancesClient.getProjectId();
for await (const rule of client.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('tsgapic-firewall')
) {
console.info(`deleting stale firewall ${rule.name}`);
await client.delete({
project: projectId,
firewall: rule.name,
});
}
}
NAME = generateName('firewall');
});

Expand All @@ -155,6 +188,9 @@ describe('Compute', () => {
});

it('create and fetch firewall, test capital letter field like "IPProtocol"', async function () {
this.retries(3);
await delay(this.test);

this.timeout(10 * 60 * 1000);
const resource = {
name: NAME,
Expand Down

0 comments on commit 21daed5

Please sign in to comment.