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

Add SDK server HTTP API test #1079

Merged

Conversation

aLekSer
Copy link
Collaborator

@aLekSer aLekSer commented Sep 26, 2019

Add conformance test for Rest API SDK server port 59358.
Does not contain swagger pregenerated files. Switched Go file to other
file extension, because it is not possible to exclude one file from
GolangCI linter run.

For #927

@aLekSer
Copy link
Collaborator Author

aLekSer commented Sep 26, 2019

I am trying to avoid autogenerated code from including to this PR. So I generate swagger folder inside docker. And clean all files using clean command.
There is an issue in golangci-lint that it is not possible not to include all dependent files to the PR:
golangci/golangci-lint#301
That's why I have added .go.nolint extension and copy file write before an execution using go run.
Other ways to resolve an issue with golangci-lint limitations would be:

  1. Use Node JS client code, which would run all queries
  2. Add Swagger auto generated code to Agones repo
  3. Use bash script with curl

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: 12c7eadd-db95-4cd9-a1a2-ae8ff8b2d38d

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: 4603a107-eb07-4de1-a960-7a155c5f8c5f

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: ace3b3a2-ef72-45b9-8e63-0054141b5b9d

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 957d39ed-fd87-4d32-b8eb-47a9d3e54843

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:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1079/head:pr_1079 && git checkout pr_1079
  • helm install install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.1.0-feb78e3

@aLekSer
Copy link
Collaborator Author

aLekSer commented Oct 7, 2019

/assign @roberthbailey
This is an HTTP endpoint test.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: a880bf40-bc36-4d32-8794-ad35adf1db44

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:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1079/head:pr_1079 && git checkout pr_1079
  • helm install install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.1.0-dbdb640

@aLekSer aLekSer force-pushed the feature/sdk-server-rest-test branch from dbdb640 to de1259a Compare October 7, 2019 18:14
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: fe9e76c6-b5d7-407a-b9a4-ace613464d2c

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:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1079/head:pr_1079 && git checkout pr_1079
  • helm install install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.1.0-de1259a

@aLekSer aLekSer force-pushed the feature/sdk-server-rest-test branch from de1259a to bb0d420 Compare October 7, 2019 21:21
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 31b66424-d8d3-429e-a561-a7dcbd7a58d6

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:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1079/head:pr_1079 && git checkout pr_1079
  • helm install install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.1.0-bb0d420

@roberthbailey
Copy link
Member

Can you explain why http-api-test.go.nolint can't pass the linter?

Copy link
Member

@roberthbailey roberthbailey left a comment

Choose a reason for hiding this comment

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

I'm really excited to have a conformance test for the rest apis. Thanks for putting together this PR.

@@ -129,11 +133,12 @@ run-sdk-conformance-no-build: RANDOM := $(shell bash -c 'echo $$RANDOM')
run-sdk-conformance-no-build: DELAY ?= $(shell bash -c "echo $$[ ($(RANDOM) % 5 ) + 1 ]")
run-sdk-conformance-no-build: TESTS ?= ready,allocate,setlabel,setannotation,gameserver,health,shutdown,watch,reserve
run-sdk-conformance-no-build: PORT ?= 59357
Copy link
Member

Choose a reason for hiding this comment

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

If the other one is HTTP_PORT then this one should be GRPC_PORT.

if err != nil {
log.Fatalf("Error in WatchGameServer: %v\n", err)
}
uid = gs.ObjectMeta.Uid
Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/googleforgames/agones/blob/master/test/sdk/go/sdk-client-test.go sets the uid through a channel, which seems more thread safe.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Used channel as in Go SDK test.

test/sdk/restapi/http-api-test.go.nolint Outdated Show resolved Hide resolved
go func() {
gs, _, err := cli.SDKApi.WatchGameServer(ctx)
if err != nil {
log.Fatalf("Error in WatchGameServer: %v\n", err)
Copy link
Member

Choose a reason for hiding this comment

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

I think log.Fatal should only happen in the main goroutine. Can this pass the error back to the main goroutine instead of a uid to signal that it failed?

log.Fatalf("Could not SetLabel: %v\n", err)
}

time.Sleep(3 * time.Second)
Copy link
Member

Choose a reason for hiding this comment

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

there isn't a sleep between the other api calls, why one here?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe this wouldn't be necessary if you used a channel to pass back the uid (which would block).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I removed this sleep

if err != nil {
log.Fatalf("Could not SetAnnotation: %v\n", err)
}
time.Sleep(1 * time.Second)
Copy link
Member

Choose a reason for hiding this comment

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

why a sleep here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is redundant, removed

build/includes/sdk.mk Show resolved Hide resolved
@aLekSer
Copy link
Collaborator Author

aLekSer commented Oct 8, 2019

Can you explain why http-api-test.go.nolint can't pass the linter?

First of all if we add this Go file we should also add multiple files generated by Swagger. This full import:
agones.dev/agones/test/sdk/restapi/swagger
Second is that Swagger resulted auto-generated code does not pass the linter itself. It does not have comments prior to every exported function.
If it is ok to include swagger results and manually correct all linter issues in resulting code I could attach these files to this PR.

@aLekSer
Copy link
Collaborator Author

aLekSer commented Oct 8, 2019

Overall there is 69 errors in swagger generated code. Example of linting errors can be found here:

test/sdk/restapi/swagger/client.go:111:6: `typeCheckParameter` is unused (deadcode)
test/sdk/restapi/swagger/client.go:125:6: `parameterToString` is unused (deadcode)
test/sdk/restapi/swagger/client.go:335:6: `reportError` is unused (deadcode)
test/sdk/restapi/swagger/client.go:440:6: `strlen` is unused (deadcode)
test/sdk/restapi/swagger/api_sdk.go:209: 209-467 lines are duplicate of `test/sdk/restapi/swagger/api_sdk.go:298-556` (dupl)
test/sdk/restapi/swagger/api_sdk.go:298: 298-556 lines are duplicate of `test/sdk/restapi/swagger/api_sdk.go:387-645` (dupl)
test/sdk/restapi/swagger/api_sdk.go:387: 387-645 lines are duplicate of `test/sdk/restapi/swagger/api_sdk.go:476-734` (dupl)
test/sdk/restapi/swagger/api_sdk.go:476: 476-734 lines are duplicate of `test/sdk/restapi/swagger/api_sdk.go:209-467` (dupl)
test/sdk/restapi/swagger/api_sdk.go:34: 34-200 lines are duplicate of `test/sdk/restapi/swagger/api_sdk.go:654-820` (dupl)
test/sdk/restapi/swagger/api_sdk.go:654: 654-820 lines are duplicate of `test/sdk/restapi/swagger/api_sdk.go:34-200` (dupl)
test/sdk/restapi/swagger/api_sdk.go:565: 565-645 lines are duplicate of `test/sdk/restapi/swagger/api_sdk.go:654-734` (dupl)
test/sdk/restapi/swagger/client.go:425:4: ineffectual assignment to `expires` (ineffassign)

@aLekSer
Copy link
Collaborator Author

aLekSer commented Oct 8, 2019

There is one more issue with Swagger or sdk.swagger.json definition file, it generates wrong function for WatchGameServer which waits forever until the end of test, however it should receive and somehow output granular GameServer results, not wait till EOF.
Debugging this issue now.

Need to find a way to change ioutil.ReadAll() which is used in swagger into something which reads only one JSON from Body.

@aLekSer
Copy link
Collaborator Author

aLekSer commented Oct 8, 2019

One more difference in that we receive "result" key while in swagger we expect to receive nested GS fields straight away :

 {"result":{"object_meta":{"name":"local","namespace":"default","uid":"3260771541929705927","resource_version":"v1","generation":"1","creation_timestamp":"1570544129","annotations":{"annotation":"true"},"labels":{"agones.dev/sdk-creationTimestamp":"1570544129","islocal":"true"}},"status":{"state":"Allocated","address":"127.0.0.1","ports":[{"name":"default","port":7777}]}}}

@aLekSer
Copy link
Collaborator Author

aLekSer commented Oct 8, 2019

When I added new Result struct:

// A GameServer Custom Resource Definition object We will only export those resources that make the most sense. Can always expand to more as needed.
type SdkGameServer struct {
	ObjectMeta *GameServerObjectMeta `json:"object_meta,omitempty"`
	Spec *GameServerSpec `json:"spec,omitempty"`
	Status *GameServerStatus `json:"status,omitempty"`
}

type Result struct {
	Result SdkGameServer `json:"result,omitempty"`
}

And switched from ioutil.ReadAll(body) into bufio.ReadSlice(byte('\n')) test become successful.

This leads us to the need of changing sdk.swagger.json file.

@aLekSer
Copy link
Collaborator Author

aLekSer commented Oct 10, 2019

I have updated this PR and include a TODO which could be removed when Swagger json would be updated.
I was not able to get rid of clean step for this test.
Other than that this PR is good to go.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: ca6e68c5-50bb-4193-8c55-8f81c4a70d4c

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:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1079/head:pr_1079 && git checkout pr_1079
  • helm install install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.1.0-e12e769

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 0b679df4-5b94-49f9-bee8-a3dc2a20ac97

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:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1079/head:pr_1079 && git checkout pr_1079
  • helm install install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.1.0-527739f

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 369f9a53-b67b-49df-8131-6fb59216e087

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:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1079/head:pr_1079 && git checkout pr_1079
  • helm install install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.1.0-7cf1838

@aLekSer aLekSer force-pushed the feature/sdk-server-rest-test branch from 7cf1838 to b24ec55 Compare October 14, 2019 16:21
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 558a9eb3-7331-429f-8fb4-9e7f79fc4716

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:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1079/head:pr_1079 && git checkout pr_1079
  • helm install install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.1.0-b24ec55

@aLekSer aLekSer force-pushed the feature/sdk-server-rest-test branch from b24ec55 to 5f3c1d7 Compare October 14, 2019 19:13
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 13b04f2e-77e6-4354-81c0-38ab1ba3bad2

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:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1079/head:pr_1079 && git checkout pr_1079
  • helm install install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.1.0-5f3c1d7


func main() {
log.Println("Client is starting")
time.Sleep(1 * time.Second)
Copy link
Member

Choose a reason for hiding this comment

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

Is this sleep necessary? The waiting loop below should take care of startup timing differences between the test and the sdkserver.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

build/includes/sdk.mk Show resolved Hide resolved

ctx := context.Background()

// Wait for SDK server to start (5 seconds)
Copy link
Member

Choose a reason for hiding this comment

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

Change 5 -> 30 to be consistent with the SDKs?


once := true
go func() {
gs, _, err := cli.SDKApi.WatchGameServer(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

This looks like it only fires once. I see two ramifications:

  1. If the first time fails for some reason the test will fail. Should it be in a loop?
  2. The error flow shouldn't be indented

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will look closely at your suggestions tomorrow.
WatchGameServer() would not succeed currently, as it wait for closing the connection not line termination symbol (tracked here #1106 ). So I left this lines as is and they would actually work, when Swagger spec and generator would be fixed.

gs, _, err := cli.SDKApi.WatchGameServer(ctx)
log.Printf("Watch response: %+v", gs)
if err != nil {
log.Printf("Error in WatchGameServer: %v\n", err)
Copy link
Member

Choose a reason for hiding this comment

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

return (or continue if in a loop) here to keep the rest of the control flow further left.

log.Fatalf("Could not SetLabel: %v\n", err)
}

// TODO: fix WatchGameServer() HTTP API Swagger definition and remove the following lines
Copy link
Member

Choose a reason for hiding this comment

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

The go routine above writes to c as does this one. Can we delete this TODO and the below go routine? Or does the watch never fire?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The watch function does not return, mentioned this in above comment, it is waiting for EOF, and "result". Opened a ticket for that.

@aLekSer aLekSer force-pushed the feature/sdk-server-rest-test branch from 5f3c1d7 to 774c80d Compare October 15, 2019 19:33
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 0c43ac6a-a7a4-4501-bcda-0e57f9edea27

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:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1079/head:pr_1079 && git checkout pr_1079
  • helm install install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.1.0-774c80d

@roberthbailey
Copy link
Member

This PR now has a conflicting file.

@aLekSer aLekSer force-pushed the feature/sdk-server-rest-test branch from 774c80d to a8d1b39 Compare October 18, 2019 20:15
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 36f5a30b-a163-407e-a9c6-69a79692ba7a

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:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1079/head:pr_1079 && git checkout pr_1079
  • helm install install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.1.0-a8d1b39

Add conformance test for Rest API SDK server port 59358.
Does not contain swagger pregenerated files. Switched Go file to other
file extension, because it is not possible to exclude one file from
GolangCI linter run.
@aLekSer aLekSer force-pushed the feature/sdk-server-rest-test branch from a8d1b39 to b4a0b13 Compare October 19, 2019 12:15
@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 89301d9a-070b-447c-b22b-397d6d53ead1

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:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1079/head:pr_1079 && git checkout pr_1079
  • helm install install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.1.0-b4a0b13

@google-oss-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aLekSer, roberthbailey

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@google-oss-robot
Copy link

New changes are detected. LGTM label has been removed.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: a55efbe6-2f81-4b17-aba6-41adbf7587bf

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:

  • git fetch https://github.com/GoogleCloudPlatform/agones.git pull/1079/head:pr_1079 && git checkout pr_1079
  • helm install install/helm/agones --namespace agones-system --name agones --set agones.image.tag=1.1.0-3ee43ce

@roberthbailey roberthbailey merged commit 971f66f into googleforgames:master Oct 20, 2019
@markmandel markmandel added this to the 1.1.0 milestone Oct 22, 2019
@markmandel markmandel added area/tests Unit tests, e2e tests, anything to make sure things don't break kind/feature New features for Agones labels Oct 22, 2019
@aLekSer aLekSer mentioned this pull request Oct 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved area/tests Unit tests, e2e tests, anything to make sure things don't break kind/feature New features for Agones size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants