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

Upgrade Pub/Sub samples. #216

Merged
merged 3 commits into from
Sep 27, 2016
Merged

Upgrade Pub/Sub samples. #216

merged 3 commits into from
Sep 27, 2016

Conversation

jmdobry
Copy link
Member

@jmdobry jmdobry commented Sep 26, 2016

  • Switch to region tags that match other languages' samples
  • Simplify tests (cut amount of test code in half)
  • Achieved 100% code coverage (as opposed to 95.5% or whatever we've been limited to previously
  • Added sample for creating a Push Subscription
  • Begin to use ES2015 features available in the Node.js 4.5.0 LTS release

Compare to:

@codecov-io
Copy link

codecov-io commented Sep 26, 2016

Current coverage is 90.28% (diff: 100%)

Merging #216 into master will increase coverage by 72.91%

@@             master       #216   diff @@
==========================================
  Files            33         54     +21   
  Lines          1917       2347    +430   
  Methods           0          0           
  Messages          0          0           
  Branches          0          0           
==========================================
+ Hits            333       2119   +1786   
+ Misses         1584        228   -1356   
  Partials          0          0           

Powered by Codecov. Last update ecef164...4d8e931

Copy link
Contributor

@ace-n ace-n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM (other than my comments, and assuming all tests pass).

// See https://googlecloudplatform.github.io/google-cloud-node/#/docs/pubsub/latest/pubsub/subscription?method=delete
subscription.delete(function (err, apiResponse) {
// Lists all subscriptions for the topic
topic.getSubscriptions((err, subscriptions) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming that this function-calling style is sufficiently idiomatic.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

}

console.log('Got metadata for subscription: %s', subscriptionName);
return callback(null, metadata);
console.log(`Subscription ${subscription.name} created.`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Same assumption about idiomatic-ness here.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

console.log('received message: ' + message.data);
console.log(`Subscription: ${metadata.name}`);
console.log(`Topic: ${metadata.topic}`);
console.log(`Push config: %s`, metadata.pushConfig.pushEndpoint);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Nit - I'm assuming we care): is there a way to make this line consistent with the others?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

var ackIds = messages.map(function (message) {
return message.ackId;
messages.forEach((message) => {
console.log(`* ${message.id} %j %j`, message.data, message.attributes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same nit as above - do we care about consistency in how arguments to console.log are formatted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'll pull message.id out, because pulling the other two in doesn't work so well.

done();
});
after((done) => {
pubsub.subscription(subscriptionNameOne).delete(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be deleting subscriptionNameTwo as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

const output = run(`${cmd} list`, cwd);
assert.notEqual(output.indexOf(`Subscriptions:`), -1);
assert.notEqual(output.indexOf(fullSubscriptionNameOne), -1);
done();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does fullSubscriptionNameTwo show up here - and if it does, should we check for it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

// Listing is eventually consistent. Give the indexes time to update.
const output = run(`${cmd} list ${topicName}`, cwd);
assert.notEqual(output.indexOf(`Subscriptions for ${topicName}:`), -1);
assert.notEqual(output.indexOf(fullSubscriptionNameOne), -1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto to above comment (fullSubscriptionNameTwo)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

assert(console.log.calledWith('Published %d message(s)!', messageIds.length));
assert.notEqual(apiResponse, undefined);
console.log(JSON.stringify(messages, null, 2));
assert.equal(messages[0].data, message.data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming the newest message always comes first, and that we don't have to worry about message order?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pub/Sub messages are unordered (they can come in any order).

In this test environment, we know there's only one message because we just created the topic and subscription and published a single message.

assert(console.log.calledWith('Deleted topic: %s', topicName));
assert.notEqual(apiResponse, undefined);
console.log(JSON.stringify(messages, null, 2));
assert.deepEqual(messages[0].data, message);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto assumption about message order.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmdobry
Copy link
Member Author

jmdobry commented Sep 27, 2016

Regarding message ordering, I've actually got a new Pub/Sub sample in another branch that shows how to manually enforce ordering with a stateful counter.

@ace-n
Copy link
Contributor

ace-n commented Sep 27, 2016

LGTM, assuming that datastore test is better off removed than skipped. 👍

@ace-n ace-n mentioned this pull request Sep 27, 2016
@jmdobry
Copy link
Member Author

jmdobry commented Sep 27, 2016

I just removed the test because you removed the method it was testing in a previous PR. I'm not sure how we missed the test...

@jmdobry jmdobry merged commit 35b153f into master Sep 27, 2016
@jmdobry jmdobry deleted the pubsub-sample-style branch September 27, 2016 22:22
pattishin pushed a commit that referenced this pull request Nov 9, 2022
…ds (#216)

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [X] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/nodejs-game-servers/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [X] Ensure the tests and linter pass
- [X] Code coverage does not decrease (if any source code was changed)
- [X] Appropriate docs were updated (if necessary)

Fixes b:179738605 🦕
pattishin pushed a commit that referenced this pull request Nov 9, 2022
…ds (#216)

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [X] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/nodejs-game-servers/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [X] Ensure the tests and linter pass
- [X] Code coverage does not decrease (if any source code was changed)
- [X] Appropriate docs were updated (if necessary)

Fixes b:179738605 🦕
pattishin pushed a commit that referenced this pull request Nov 9, 2022
…ds (#216)

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [X] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/nodejs-game-servers/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [X] Ensure the tests and linter pass
- [X] Code coverage does not decrease (if any source code was changed)
- [X] Appropriate docs were updated (if necessary)

Fixes b:179738605 🦕
NimJay pushed a commit that referenced this pull request Nov 11, 2022
…ds (#216)

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [X] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/nodejs-game-servers/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [X] Ensure the tests and linter pass
- [X] Code coverage does not decrease (if any source code was changed)
- [X] Appropriate docs were updated (if necessary)

Fixes b:179738605 🦕
ace-n pushed a commit that referenced this pull request Nov 16, 2022
docs(samples): Adds start of region tag
ace-n pushed a commit that referenced this pull request Nov 17, 2022
docs(samples): Adds start of region tag
ahrarmonsur pushed a commit that referenced this pull request Nov 17, 2022
docs(samples): Adds start of region tag
NimJay pushed a commit that referenced this pull request Nov 19, 2022
* updated CHANGELOG.md

* updated package.json

* updated samples/package.json
NimJay pushed a commit that referenced this pull request Nov 19, 2022
* updated CHANGELOG.md

* updated package.json

* updated samples/package.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants