Skip to content

Commit 3ad89e6

Browse files
author
Benjamin E. Coe
authored
test: make tests idempotent (#201)
1 parent 705a62a commit 3ad89e6

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

container-analysis/snippets/test/containerAnalysis.test.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -303,18 +303,32 @@ describe('pubsub', () => {
303303
projectId = await client.getProjectId();
304304
formattedParent = `projects/${projectId}`;
305305
formattedNoteName = `projects/${projectId}/notes/${noteId}`;
306-
try {
307-
// attempt to create topic if missing
308-
await pubsub.createTopic(topicName);
309-
} catch (err) {
310-
console.log(`topic creation failed: ${topicName}`);
311-
}
312306
topic = pubsub.topic(topicName);
313307
});
314308

315309
describe('occurrences from pubsub subscription', () => {
316-
before(async () => {
317-
await topic.createSubscription(subscriptionId);
310+
it('should get count of occurrences from pubsub topic', async function() {
311+
this.retries(3);
312+
await delay(this.test);
313+
try {
314+
// attempt to create topic if missing
315+
await pubsub.createTopic(topicName);
316+
} catch (err) {
317+
console.log(`topic creation failed: ${topicName} ${err.message}`);
318+
if (!err.message.includes('ALREADY_EXISTS')) {
319+
throw err;
320+
}
321+
}
322+
try {
323+
await topic.createSubscription(subscriptionId);
324+
} catch (err) {
325+
console.log(
326+
`subscription creation failed: ${subscriptionId} ${err.message}`
327+
);
328+
if (!err.message.includes('ALREADY_EXISTS')) {
329+
throw err;
330+
}
331+
}
318332
const pubSubNoteReq = {
319333
parent: formattedParent,
320334
noteId: `${noteId}-pubsub`,
@@ -336,12 +350,6 @@ describe('pubsub', () => {
336350
},
337351
};
338352
await client.getGrafeasClient().createNote(pubSubNoteReq);
339-
});
340-
341-
it('should get count of occurrences from pubsub topic', async function () {
342-
this.retries(3);
343-
await delay(this.test);
344-
345353
const occurrenceCount = 3;
346354
const pubSubOccurrenceReq = {
347355
parent: formattedParent,
@@ -389,7 +397,7 @@ describe('pubsub', () => {
389397
assert.match(output, /Polled [1-9]+ occurrences/);
390398
});
391399

392-
it('should delete the pubsub subscription', async function () {
400+
it('should delete the pubsub subscription', async function() {
393401
this.retries(3);
394402
await delay(this.test);
395403

0 commit comments

Comments
 (0)