Skip to content

Commit

Permalink
test: make tests idempotent (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe authored Apr 23, 2020
1 parent 705a62a commit 3ad89e6
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions container-analysis/snippets/test/containerAnalysis.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,18 +303,32 @@ describe('pubsub', () => {
projectId = await client.getProjectId();
formattedParent = `projects/${projectId}`;
formattedNoteName = `projects/${projectId}/notes/${noteId}`;
try {
// attempt to create topic if missing
await pubsub.createTopic(topicName);
} catch (err) {
console.log(`topic creation failed: ${topicName}`);
}
topic = pubsub.topic(topicName);
});

describe('occurrences from pubsub subscription', () => {
before(async () => {
await topic.createSubscription(subscriptionId);
it('should get count of occurrences from pubsub topic', async function() {
this.retries(3);
await delay(this.test);
try {
// attempt to create topic if missing
await pubsub.createTopic(topicName);
} catch (err) {
console.log(`topic creation failed: ${topicName} ${err.message}`);
if (!err.message.includes('ALREADY_EXISTS')) {
throw err;
}
}
try {
await topic.createSubscription(subscriptionId);
} catch (err) {
console.log(
`subscription creation failed: ${subscriptionId} ${err.message}`
);
if (!err.message.includes('ALREADY_EXISTS')) {
throw err;
}
}
const pubSubNoteReq = {
parent: formattedParent,
noteId: `${noteId}-pubsub`,
Expand All @@ -336,12 +350,6 @@ describe('pubsub', () => {
},
};
await client.getGrafeasClient().createNote(pubSubNoteReq);
});

it('should get count of occurrences from pubsub topic', async function () {
this.retries(3);
await delay(this.test);

const occurrenceCount = 3;
const pubSubOccurrenceReq = {
parent: formattedParent,
Expand Down Expand Up @@ -389,7 +397,7 @@ describe('pubsub', () => {
assert.match(output, /Polled [1-9]+ occurrences/);
});

it('should delete the pubsub subscription', async function () {
it('should delete the pubsub subscription', async function() {
this.retries(3);
await delay(this.test);

Expand Down

0 comments on commit 3ad89e6

Please sign in to comment.