From e54633e28049f50bf632e9e6b699b1fd3ddb2ed9 Mon Sep 17 00:00:00 2001 From: Dave Gramlich Date: Fri, 25 Jan 2019 23:26:52 -0500 Subject: [PATCH 1/2] fix(sample): factor setTimeout jitter into assertion --- samples/system-test/topics.test.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/samples/system-test/topics.test.js b/samples/system-test/topics.test.js index 32549c63b..b05cea82a 100644 --- a/samples/system-test/topics.test.js +++ b/samples/system-test/topics.test.js @@ -167,9 +167,14 @@ describe('topics', () => { }" -w ${expectedWait}` ); const receivedMessage = await _pullOneMessage(subscription); + const publishTime = Date.parse(receivedMessage.publishTime); + const actualWait = publishTime - startTime; + assert.strictEqual(receivedMessage.data.toString(), expectedMessage.data); - assert.strictEqual(publishTime - startTime > expectedWait, true); + // setTimeout isn't so reliable to publish messages EXACTLY at 1000ms, + // so we should consider anything above 900 as passing. + assert(actualWait >= (expectedWait - 100)); }); it('should publish with retry settings', async () => { From c7208ff40fa86034ae56ec23f0fdb90f8b9a107d Mon Sep 17 00:00:00 2001 From: Dave Gramlich Date: Fri, 25 Jan 2019 23:35:27 -0500 Subject: [PATCH 2/2] lint errors, oh my! --- samples/system-test/topics.test.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/samples/system-test/topics.test.js b/samples/system-test/topics.test.js index b05cea82a..edd9a821f 100644 --- a/samples/system-test/topics.test.js +++ b/samples/system-test/topics.test.js @@ -155,7 +155,7 @@ describe('topics', () => { }); it('should publish with specific batch settings', async () => { - const expectedWait = 1000; + const waitTime = 1000; const [subscription] = await pubsub .topic(topicNameOne) .subscription(subscriptionNameThree) @@ -164,17 +164,18 @@ describe('topics', () => { await exec( `${cmd} publish-batch ${topicNameOne} "${ expectedMessage.data - }" -w ${expectedWait}` + }" -w ${waitTime}` ); const receivedMessage = await _pullOneMessage(subscription); const publishTime = Date.parse(receivedMessage.publishTime); const actualWait = publishTime - startTime; - - assert.strictEqual(receivedMessage.data.toString(), expectedMessage.data); // setTimeout isn't so reliable to publish messages EXACTLY at 1000ms, // so we should consider anything above 900 as passing. - assert(actualWait >= (expectedWait - 100)); + const expectedWait = waitTime - 100; + + assert.strictEqual(receivedMessage.data.toString(), expectedMessage.data); + assert(actualWait >= expectedWait); }); it('should publish with retry settings', async () => {