-
Notifications
You must be signed in to change notification settings - Fork 830
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
Nodejs counters and lists #3726
Merged
Merged
Changes from 15 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
e2d614d
Add getCounterCount
steven-supersolid 276201d
Add types
steven-supersolid 7f2510c
Implement incrementCounter
steven-supersolid ba75ad0
Implement decrementCounter
steven-supersolid f7f3308
Implement setCounterCount
steven-supersolid c98a9bc
Implement getCounterCapacity
steven-supersolid 1a45bc1
Implement setCounterCapacity
steven-supersolid 77e2f33
Implement list requests
steven-supersolid ab4e918
Fix int64 values
steven-supersolid 2f35140
Example usage
steven-supersolid f3a4992
Remove boolean return types. Update packages
steven-supersolid b0a1666
Update example, fix SDK and tests
steven-supersolid c8979d8
update conformance test
steven-supersolid 6496474
Merge remote-tracking branch 'upstream/main' into nodejs.CountsAndLists
steven-supersolid 4104682
Update package-lock.json
steven-supersolid 6a56575
Update gameserver-counts-and-lists.yaml
steven-supersolid 999c31d
Split beta methods out of alpha
steven-supersolid 2c5fc4b
Merge branch 'main' into nodejs.CountsAndLists
steven-supersolid a786e2a
Fix typo and update example
steven-supersolid 795d0e7
Merge branch 'main' into nodejs.CountsAndLists
steven-supersolid e8075db
Update testSDKClient.js
steven-supersolid 1f9ad51
Output arguments test
steven-supersolid 68eeea4
Update make file for Node.js conformance tests
steven-supersolid e79c64a
Enable standard counts and lists tests
steven-supersolid e7d5c6c
alpha --> beta
steven-supersolid 935b47a
Update nodejs-simple
steven-supersolid ca61c4b
Update build/includes/sdk.mk
steven-supersolid 441aa48
Merge branch 'main' into nodejs.CountsAndLists
steven-supersolid 495abda
Merge branch 'main' into nodejs.CountsAndLists
steven-supersolid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
# Copyright 2020 Google LLC All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
apiVersion: agones.dev/v1 | ||
kind: GameServer | ||
metadata: | ||
generateName: simple-game-server- | ||
spec: | ||
ports: | ||
- name: default | ||
portPolicy: Dynamic | ||
containerPort: 7654 | ||
counters: | ||
games: | ||
count: 1 | ||
capacity: 10 | ||
lists: | ||
rooms: | ||
capacity: 5 | ||
values: | ||
- room1 | ||
- room2 | ||
template: | ||
spec: | ||
containers: | ||
- name: simple-game-server | ||
image: us-docker.pkg.dev/agones-images/examples/simple-game-server:0.27 | ||
resources: | ||
requests: | ||
memory: 64Mi | ||
cpu: 20m | ||
limits: | ||
memory: 64Mi | ||
cpu: 20m | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ const {setTimeout} = require('timers/promises'); | |
const DEFAULT_TIMEOUT = 60; | ||
const MAX_TIMEOUT = 2147483; | ||
|
||
const connect = async (timeout, enableAlpha) => { | ||
const connect = async (timeout, enableAlpha, enableCountsAndLists) => { | ||
let agonesSDK = new AgonesSDK(); | ||
|
||
let lifetimeInterval; | ||
|
@@ -56,32 +56,37 @@ const connect = async (timeout, enableAlpha) => { | |
process.exit(0); | ||
}); | ||
|
||
await setTimeout(10000); | ||
await setTimeout(5000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shortening the delay as there as so many calls now |
||
console.log('Setting a label'); | ||
await agonesSDK.setLabel('test-label', 'test-value'); | ||
|
||
await setTimeout(10000); | ||
await setTimeout(5000); | ||
console.log('Setting an annotation'); | ||
await agonesSDK.setAnnotation('test-annotation', 'test value'); | ||
|
||
await setTimeout(10000); | ||
await setTimeout(5000); | ||
console.log('Marking server as ready...'); | ||
await agonesSDK.ready(); | ||
|
||
await setTimeout(10000); | ||
await setTimeout(5000); | ||
console.log('Allocating'); | ||
await agonesSDK.allocate(); | ||
|
||
await setTimeout(10000); | ||
await setTimeout(5000); | ||
console.log('Reserving for 10 seconds'); | ||
await agonesSDK.reserve(10); | ||
await setTimeout(20000); | ||
await setTimeout(15000); | ||
|
||
if (enableAlpha) { | ||
console.log('Running alpha suite'); | ||
await runAlphaSuite(agonesSDK); | ||
} | ||
|
||
if (enableCountsAndLists) { | ||
console.log('Running counts and lists suite'); | ||
await runCountAndListsSuite(agonesSDK); | ||
} | ||
|
||
if (timeout === 0) { | ||
do { | ||
await setTimeout(MAX_TIMEOUT); | ||
|
@@ -93,12 +98,12 @@ const connect = async (timeout, enableAlpha) => { | |
console.log('Shutting down...'); | ||
agonesSDK.shutdown(); | ||
|
||
await setTimeout(10000); | ||
await setTimeout(5000); | ||
console.log('Closing connection to SDK server'); | ||
clearInterval(healthInterval); | ||
agonesSDK.close(); | ||
|
||
await setTimeout(10000); | ||
await setTimeout(5000); | ||
console.log('Exiting'); | ||
clearInterval(lifetimeInterval); | ||
|
||
|
@@ -113,58 +118,126 @@ const connect = async (timeout, enableAlpha) => { | |
}; | ||
|
||
const runAlphaSuite = async (agonesSDK) => { | ||
await setTimeout(10000); | ||
await setTimeout(5000); | ||
console.log('Setting capacity'); | ||
await agonesSDK.alpha.setPlayerCapacity(64); | ||
|
||
await setTimeout(10000); | ||
await setTimeout(5000); | ||
console.log('Getting capacity'); | ||
let result = await agonesSDK.alpha.getPlayerCapacity(); | ||
console.log(`result: ${result}`); | ||
|
||
await setTimeout(10000); | ||
await setTimeout(5000); | ||
console.log('Connecting a player'); | ||
result = await agonesSDK.alpha.playerConnect('firstPlayerID'); | ||
console.log(`result: ${result}`); | ||
|
||
await setTimeout(10000); | ||
await setTimeout(5000); | ||
console.log('Connecting a duplicate player'); | ||
result = await agonesSDK.alpha.playerConnect('firstPlayerID'); | ||
console.log(`result: ${result}`); | ||
|
||
await setTimeout(10000); | ||
await setTimeout(5000); | ||
console.log('Connecting another player'); | ||
await agonesSDK.alpha.playerConnect('secondPlayerID'); | ||
|
||
await setTimeout(10000); | ||
await setTimeout(5000); | ||
console.log('Getting player count'); | ||
result = await agonesSDK.alpha.getPlayerCount(); | ||
console.log(`result: ${result}`); | ||
|
||
await setTimeout(10000); | ||
await setTimeout(5000); | ||
console.log('Finding if firstPlayerID connected'); | ||
result = await agonesSDK.alpha.isPlayerConnected('firstPlayerID'); | ||
console.log(`result: ${result}`); | ||
|
||
await setTimeout(10000); | ||
await setTimeout(5000); | ||
console.log('Getting connected players'); | ||
result = await agonesSDK.alpha.getConnectedPlayers(); | ||
console.log(`result: ${result}`); | ||
|
||
await setTimeout(10000); | ||
await setTimeout(5000); | ||
console.log('Disconnecting a player'); | ||
result = await agonesSDK.alpha.playerDisconnect('firstPlayerID'); | ||
console.log(`result: ${result}`); | ||
|
||
await setTimeout(10000); | ||
await setTimeout(5000); | ||
console.log('Disconnecting the same player'); | ||
result = await agonesSDK.alpha.playerDisconnect('firstPlayerID'); | ||
console.log(`result: ${result}`); | ||
|
||
await setTimeout(5000); | ||
console.log('Setting counter capacity'); | ||
result = await agonesSDK.alpha.setCounterCapacity('testCounter', 10); | ||
console.log(`result: ${result}`); | ||
}; | ||
|
||
const runCountAndListsSuite = async (agonesSDK) => { | ||
let result; | ||
|
||
await setTimeout(5000); | ||
console.log('Getting counter count'); | ||
result = await agonesSDK.alpha.getCounterCount('games'); | ||
console.log(`result: ${result}`); | ||
|
||
await setTimeout(5000); | ||
console.log('Incrementing counter'); | ||
await agonesSDK.alpha.incrementCounter('games', 1); | ||
|
||
await setTimeout(5000); | ||
console.log('Decrementing counter'); | ||
await agonesSDK.alpha.decrementCounter('games', 1); | ||
|
||
await setTimeout(5000); | ||
console.log('Setting counter count'); | ||
await agonesSDK.alpha.setCounterCount('games', 2); | ||
|
||
await setTimeout(5000); | ||
console.log('Getting counter capacity'); | ||
result = await agonesSDK.alpha.getCounterCapacity('games'); | ||
console.log(`result: ${result}`); | ||
|
||
await setTimeout(5000); | ||
console.log('Setting counter capacity'); | ||
await agonesSDK.alpha.setCounterCapacity('games', 200); | ||
|
||
await setTimeout(5000); | ||
console.log('Getting list capacity'); | ||
result = await agonesSDK.alpha.getListCapacity('rooms'); | ||
console.log(`result: ${result}`); | ||
|
||
await setTimeout(5000); | ||
console.log('Setting list capacity'); | ||
await agonesSDK.alpha.setListCapacity('rooms', 10); | ||
|
||
await setTimeout(5000); | ||
console.log('Getting list contains'); | ||
result = await agonesSDK.alpha.listContains('rooms', 'room1'); | ||
console.log(`result: ${result}`); | ||
|
||
await setTimeout(5000); | ||
console.log('Getting list length'); | ||
result = await agonesSDK.alpha.getListLength('rooms'); | ||
console.log(`result: ${result}`); | ||
|
||
await setTimeout(5000); | ||
console.log('Getting list values'); | ||
result = await agonesSDK.alpha.getListValues('rooms'); | ||
console.log(`result: ${result}`); | ||
|
||
await setTimeout(5000); | ||
console.log('Appending list value'); | ||
await agonesSDK.alpha.appendListValue('rooms', 'room3'); | ||
|
||
await setTimeout(5000); | ||
console.log('Deleting list value'); | ||
await agonesSDK.alpha.deleteListValue('rooms', 'room3'); | ||
}; | ||
|
||
let args = process.argv.slice(2); | ||
let timeout = DEFAULT_TIMEOUT; | ||
let enableAlpha = false; | ||
let enableCountsAndLists = false; | ||
|
||
for (let arg of args) { | ||
let [argName, argValue] = arg.split('='); | ||
|
@@ -173,7 +246,8 @@ for (let arg of args) { | |
|
||
Options: | ||
--timeout=...\t\tshutdown timeout in seconds. Use 0 to never shut down | ||
--alpha\t\t\tenable alpha features`); | ||
--alpha\t\t\tenable alpha features | ||
--countsandlists\tenable counts and lists features`); | ||
return; | ||
} | ||
if (argName === '--timeout') { | ||
|
@@ -194,6 +268,11 @@ Options: | |
console.log('Enabling alpha features!'); | ||
enableAlpha = true; | ||
} | ||
|
||
if (argName === '--countsandlists') { | ||
console.log('Enabling counts and lists features!'); | ||
enableCountsAndLists = true; | ||
} | ||
} | ||
|
||
connect(timeout, enableAlpha); | ||
connect(timeout, enableAlpha, enableCountsAndLists); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 made this to test with the local server but neither the counter or list can be found, so perhaps the structure is incorrect?
I started with
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.
Did you want the example to have the same counter and list as the local SDK Server? The sample local SDK server counters is "rooms" and lists is "players"
agones/pkg/sdkserver/localsdk.go
Lines 76 to 83 in 4b2910b
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.
Thank you, that's what I needed, so can perhaps remove this file and update the example