-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
b3edcf9
to
e5ced9e
Compare
Current coverage is 90.28% (diff: 100%)@@ 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
|
66babd4
to
21fb5ab
Compare
There was a problem hiding this 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) => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.`); |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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(() => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
)
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #216 (comment)
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. |
21fb5ab
to
eae0a6f
Compare
LGTM, assuming that datastore test is better off removed than skipped. 👍 |
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... |
…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 🦕
…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 🦕
…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 🦕
…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 🦕
docs(samples): Adds start of region tag
docs(samples): Adds start of region tag
docs(samples): Adds start of region tag
* updated CHANGELOG.md * updated package.json * updated samples/package.json
* updated CHANGELOG.md * updated package.json * updated samples/package.json
Compare to: