-
Notifications
You must be signed in to change notification settings - Fork 820
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
Implement block on connect with Rust+Node.js SDK #953
Implement block on connect with Rust+Node.js SDK #953
Conversation
sleep 2s && DOCKER_RUN_ARGS="--network=host $(DOCKER_RUN_ARGS)" COMMAND=sdktest $(MAKE) run-sdk-command & \ | ||
docker run -p 59357:59357 -e "ADDRESS=" \ | ||
DOCKER_RUN_ARGS="--network=host $(DOCKER_RUN_ARGS)" COMMAND=sdktest $(MAKE) run-sdk-command & \ | ||
sleep $(DELAY) && docker run -p 59357:59357 -e "ADDRESS=" \ |
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.
@aLekSer wdyt of this approach?
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.
yes, this one much better
@@ -43,7 +46,24 @@ impl Sdk { | |||
.connect(&addr); | |||
let cli = sdk_grpc::SdkClient::new(ch); | |||
let req = sdk::Empty::new(); | |||
let _ = cli.ready(&req).map(Box::new)?; | |||
|
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.
@thara would love your review of my Rust code. I'm a little.... rusty 🙄 🤣 🦀
Build Failed 😱 Build Id: 8d25b56d-ccaf-4288-aaa3-5a05315eb41c To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
Build Failed 😱 Build Id: 1f485ad6-2ece-44b8-939b-e45e44027942 To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
Hmnn. Not sure why we are failing. Will look into it. I think it's failing on the nodejs version - not sure I'm following the logs well. |
Yep, can confirm - it's the node client - I assumed it blocked on connect, but it doesn't look like it. I'm hunting it down by @steven-supersolid if you have the code needed to block on connect, that would be awesome. |
https://grpc.github.io/grpc/node/grpc.Client.html#waitForReady__anchor looks like what I need, but now trying to work out how to apply it in an async language :D |
fe0630d
to
7faca63
Compare
Here's my attempt: But I keep getting:
But it doesn't look like it actually waiting for the deadline. Not quite sure why it isn't waiting. |
Worked it out - but I should write some docs on it 👍 (hopefully it passes). Would still love a review of my node.js though. I'll update my PR description too. |
7faca63
to
76bc0c3
Compare
Build Failed 😱 Build Id: bea5726c-71ac-4e16-bba0-cae5dbce6ed6 To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
sdks/nodejs/src/agonesSDK.js
Outdated
|
||
async connect() { | ||
return new Promise((resolve, reject) => { | ||
this.client.waitForReady((new Date).getTime() + 30000, (error) => { |
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.
Minor but Date.now()
is the more succinct way of getting the current system time. So Date.now() + 30000
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.
Done!
@@ -23,7 +23,20 @@ class AgonesSDK { | |||
this.healthStream = undefined; | |||
this.emitters = []; | |||
} | |||
async close(){ | |||
|
|||
async connect() { |
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.
We should add a test for this to maintain code coverage. Please let me know if you'd like me to add, e.g. separate PR?
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.
Not sure how we are going to make a unit test for this, when there is nothing to connect to, but I will have a look, see if I can work out a way.
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.
Aha, got it - there is a mocking library you use to mock out the client. On 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.
Done! PTAL.
sdks/nodejs/src/agonesSDK.js
Outdated
|
||
async connect() { | ||
return new Promise((resolve, reject) => { | ||
this.client.waitForReady((new Date).getTime() + 30000, (error) => { |
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 would be tempted to add the timeout to the constructor with a default value. E.g.
constructor(timeout = 30000) {
this.timeout = timeout
...
use later as Date.now() + this.timeout
Or if you like pass in as seconds and multiply by 1000 in the constructor
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.
All other SDKs timeout by 30 seconds - we control the SDK server, so not personally seeing a good reason to make this configurable. I can't think of a use case in which someone would want to make this larger/smaller?
@@ -23,7 +23,20 @@ class AgonesSDK { | |||
this.healthStream = undefined; | |||
this.emitters = []; | |||
} | |||
async close(){ | |||
|
|||
async connect() { |
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.
We should also update the docs.
I will look at generating API docs automatically for Node.js soon (maybe next weekend)
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 - on my todo list.
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.
Done!. PTAL.
Build Succeeded 👏 Build Id: 2cc0b4c5-5037-4f44-8d69-451ad7253888 The following development artifacts have been built, and will exist for the next 30 days:
A preview of the website (the last 30 builds are retained): To install this version:
|
4717b2c
to
22cd467
Compare
Build Succeeded 👏 Build Id: 480575f8-f3ed-48ab-8a38-0a4801985710 The following development artifacts have been built, and will exist for the next 30 days:
A preview of the website (the last 30 builds are retained): To install this version:
|
|
||
```javascript | ||
const AgonesSDK = require('agones'); | ||
|
||
let agonesSDK = new AgonesSDK(); | ||
``` | ||
|
||
{{% feature publishVersion="0.12.0" %}} | ||
To connect to the SDK server, either local or when running on Agones, run the `sdk.connect()` method. | ||
This will block for up to 30 seconds if the SDK server has not yet started. If the connection cannot be made, |
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.
Minor but would call out that it's an async
method that will resolve
once connected or reject
on error or if no connection can be made after 30 seconds. Technically it will block execution of the calling code if that uses await
but does not block the Node.js event loop. I try to stray away from using the term block for async code and would reserve that for synchronous code that does block the event loop e.g. heavy calculation/loop
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.
Thanks! Would definitely like to use more canonical language for node.js - will make this change.
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.
Done!
I just realised we will also need to update the example in |
Yep - I think we can do this in a separate PR though - I think this one has enough in it already. |
f863909
to
2904081
Compare
Build Succeeded 👏 Build Id: 90c29092-06b5-4e7b-9e25-17b661b27e58 The following development artifacts have been built, and will exist for the next 30 days:
A preview of the website (the last 30 builds are retained): To install this version:
|
2904081
to
369db9b
Compare
sdks/nodejs/src/agonesSDK.js
Outdated
async close() { | ||
if (this.healthStream !== undefined) { | ||
if (this.healthStream !== undefined){ |
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: you seem to have lost a space on this line
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.
ARG! Fixing.
Build Succeeded 👏 Build Id: 7bf53655-a6ab-4a37-b5c5-477af5a02a8d The following development artifacts have been built, and will exist for the next 30 days:
A preview of the website (the last 30 builds are retained): To install this version:
|
- Uses a simple polling mechanism to confirm the connection is live - Add `ready` to the SDK documentation. - Implements and documents a sdk.connect() function - Tweaks the conformance tests to add a random delay to ensure future testing of SDK blocking. Fixes googleforgames#938
369db9b
to
46d75e4
Compare
Build Succeeded 👏 Build Id: b7a57a5c-d926-400f-8301-012d6811e6ac The following development artifacts have been built, and will exist for the next 30 days:
A preview of the website (the last 30 builds are retained): To install this version:
|
@steven-supersolid & @thara - I'm going to merge this so that it gets in before the 0.12.0 release candidate cut. If you have any other review comments, feel free to send a followup PR to fix things up. |
Rust
ready
to the SDK documentation.Node.js
Make
testing of SDK blocking.
Fixes #938