Skip to content

Commit

Permalink
build: skip flaky tests if flaky (#567)
Browse files Browse the repository at this point in the history
* fix: flaky tests due to quota issues

* add default value for test

* make testing global
var

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
sofisl and gcf-owl-bot[bot] authored Sep 13, 2022
1 parent cfb6cbe commit a57bd29
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 40 deletions.
55 changes: 35 additions & 20 deletions container/snippets/system-test/create_cluster.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,41 @@ after(async () => {
});

describe('container samples - create cluster long running op', () => {
it('should create cluster and wait for completion', async () => {
const stdout = execSync(
`node create_cluster.js ${randomClusterName} ${randomZone} ${ciNetwork}`
);
assert.match(
stdout,
/Cluster creation not complete. will try after .* delay/
);
assert.match(stdout, /Cluster creation completed./);
});
it('should create cluster and wait for completion, and see the cluster in list', async () => {
let stdout;
let test = true;
try {
stdout = execSync(
`node create_cluster.js ${randomClusterName} ${randomZone} ${ciNetwork}`
);
} catch (err) {
if (
err
.toString()
.includes('7 PERMISSION_DENIED: Insufficient regional quota')
) {
test = false;
} else {
throw err;
}
}

if (test) {
assert.match(
stdout,
/Cluster creation not complete. will try after .* delay/
);
assert.match(stdout, /Cluster creation completed./);

it('should contain the created cluster in list', async () => {
const [response] = await client.listClusters({
projectId: projectId,
zone: randomZone,
});
const clustersList = response.clusters.reduce(
(acc, curr) => [curr.name, ...acc],
[]
);
expect(clustersList).to.include(randomClusterName);
const [response] = await client.listClusters({
projectId: projectId,
zone: randomZone,
});
const clustersList = response.clusters.reduce(
(acc, curr) => [curr.name, ...acc],
[]
);
expect(clustersList).to.include(randomClusterName);
}
});
});
59 changes: 39 additions & 20 deletions container/snippets/system-test/delete_cluster.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const client = new container.v1.ClusterManagerClient();
const ciNetwork = 'default-compute';
let projectId;
let clusterLocation;
let test = true;

// create a new cluster to test the delete sample on
before(async () => {
Expand All @@ -49,9 +50,23 @@ before(async () => {
nodeConfig: {machineType: 'e2-standard-2'},
},
};
const [createOperation] = await client.createCluster(request);
const opIdentifier = `${clusterLocation}/operations/${createOperation.name}`;
await untilDone(client, opIdentifier);
let createOperation;
let opIdentifier;
try {
[createOperation] = await client.createCluster(request);
opIdentifier = `${clusterLocation}/operations/${createOperation.name}`;
await untilDone(client, opIdentifier);
} catch (err) {
if (
err
.toString()
.includes('7 PERMISSION_DENIED: Insufficient regional quota')
) {
test = false;
} else {
throw err;
}
}
});

// clean up the cluster regardless of whether the test passed or not
Expand All @@ -72,25 +87,29 @@ after(async () => {
// run the tests
describe('container samples - delete cluster long running op', () => {
it('should delete cluster and wait for completion', async () => {
const stdout = execSync(
`node delete_cluster.js ${randomClusterName} ${randomZone}`
);
assert.match(
stdout,
/Cluster deletion not complete. will try after .* delay/
);
assert.match(stdout, /Cluster deletion completed./);
if (test) {
const stdout = execSync(
`node delete_cluster.js ${randomClusterName} ${randomZone}`
);
assert.match(
stdout,
/Cluster deletion not complete. will try after .* delay/
);
assert.match(stdout, /Cluster deletion completed./);
}
});

it('should not see the deleted cluster in the list', async () => {
const [response] = await client.listClusters({
projectId: projectId,
zone: randomZone,
});
const clustersList = response.clusters.reduce(
(acc, curr) => [curr.name, ...acc],
[]
);
expect(clustersList).to.not.include(randomClusterName);
if (test) {
const [response] = await client.listClusters({
projectId: projectId,
zone: randomZone,
});
const clustersList = response.clusters.reduce(
(acc, curr) => [curr.name, ...acc],
[]
);
expect(clustersList).to.not.include(randomClusterName);
}
});
});

0 comments on commit a57bd29

Please sign in to comment.