From c1555556ed80ba870dc2d1527a263a9d74f48b57 Mon Sep 17 00:00:00 2001 From: "Benjamin E. Coe" Date: Fri, 3 Apr 2020 14:39:03 -0700 Subject: [PATCH] test: there's a race condition emptying queue (#175) --- .../snippets/test/containerAnalysis.test.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/container-analysis/snippets/test/containerAnalysis.test.js b/container-analysis/snippets/test/containerAnalysis.test.js index 20ebcedfbe..38a6952a69 100644 --- a/container-analysis/snippets/test/containerAnalysis.test.js +++ b/container-analysis/snippets/test/containerAnalysis.test.js @@ -343,8 +343,8 @@ describe('pubsub', () => { await pubsub.subscription(subscriptionId).delete(); }); - it('should get accurate count of occurrences from pubsub topic', async () => { - const expectedNum = 3; + it('should get count of occurrences from pubsub topic', async () => { + const occurrenceCount = 3; const pubSubOccurrenceReq = { parent: formattedParent, occurrence: { @@ -372,14 +372,8 @@ describe('pubsub', () => { `node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"` ); - // make sure empty - const empty = execSync( - `node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"` - ); - - assert.include(empty, 'Polled 0 occurrences'); // create test occurrences - for (let i = 0; i < expectedNum; i++) { + for (let i = 0; i < occurrenceCount; i++) { const [ pubSubOccurrence, ] = await client.getGrafeasClient().createOccurrence(pubSubOccurrenceReq); @@ -391,7 +385,7 @@ describe('pubsub', () => { `node occurrencePubSub.js "${projectId}" "${subscriptionId}" "${timeoutSeconds}"` ); - // make sure pubsub number matches - assert.include(output, `Polled ${expectedNum} occurrences`); + // ensure that our occcurences were enqueued: + assert.match(output, /Polled [1-9]+ occurrences/); }); });