Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sample): factor setTimeout jitter into assertion #449

Merged
merged 2 commits into from
Jan 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions samples/system-test/topics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -164,12 +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;
// setTimeout isn't so reliable to publish messages EXACTLY at 1000ms,
// so we should consider anything above 900 as passing.
const expectedWait = waitTime - 100;

assert.strictEqual(receivedMessage.data.toString(), expectedMessage.data);
assert.strictEqual(publishTime - startTime > expectedWait, true);
assert(actualWait >= expectedWait);
});

it('should publish with retry settings', async () => {
Expand Down