From 1e293d52652a0e4076a2505f962e689579f2c8f4 Mon Sep 17 00:00:00 2001 From: Dave Gramlich Date: Fri, 22 Feb 2019 15:10:10 -0500 Subject: [PATCH] test(samples): correctly handle publishTime value: --- samples/system-test/subscriptions.test.js | 6 +++++- samples/system-test/topics.test.js | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/samples/system-test/subscriptions.test.js b/samples/system-test/subscriptions.test.js index 715d74d06..814350da3 100644 --- a/samples/system-test/subscriptions.test.js +++ b/samples/system-test/subscriptions.test.js @@ -20,7 +20,11 @@ const {assert} = require('chai'); const execa = require('execa'); const uuid = require('uuid'); -const exec = async cmd => (await execa.shell(cmd)).stdout; +async function exec(cmd) { + const promise = execa.shell(cmd); + promise.stdout.pipe(process.stdout); + return (await promise).stdout; +} describe('subscriptions', () => { const projectId = process.env.GCLOUD_PROJECT; diff --git a/samples/system-test/topics.test.js b/samples/system-test/topics.test.js index b1d8611bc..ff4cb3663 100644 --- a/samples/system-test/topics.test.js +++ b/samples/system-test/topics.test.js @@ -20,8 +20,13 @@ const {assert} = require('chai'); const execa = require('execa'); const uuid = require('uuid'); +async function exec(cmd) { + const promise = execa.shell(cmd); + promise.stdout.pipe(process.stdout); + return (await promise).stdout; +} + describe('topics', () => { - const exec = async cmd => (await execa.shell(cmd)).stdout; const projectId = process.env.GCLOUD_PROJECT; const pubsub = new PubSub({projectId}); const topicNameOne = `nodejs-docs-samples-test-${uuid.v4()}`; @@ -166,17 +171,12 @@ describe('topics', () => { expectedMessage.data }" -w ${waitTime}` ); - const receivedMessage = await _pullOneMessage(subscription); - const publishTime = Date.parse(receivedMessage.publishTime); - // publishTime contains whole seconds (ends with 000), - // so we allow the difference to be up to 1 second less - // than we expect. - const actualWait = publishTime - startTime; - const expectedWait = waitTime - 1000; + const {data, publishTime} = await _pullOneMessage(subscription); + const actualWait = publishTime.getTime() - startTime; - assert.strictEqual(receivedMessage.data.toString(), expectedMessage.data); - assert(actualWait >= expectedWait); + assert.strictEqual(data.toString(), expectedMessage.data); + assert(actualWait >= waitTime); }); it('should publish with retry settings', async () => {