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

Initial version of SDK conformance Testing framework for Golang, NodeJS and others #845

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions build/build-sdk-conformance/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2019 Google Inc. 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.
FROM golang:latest

RUN apt-get update && \
apt-get install -y wget jq && \
apt-get clean

# install go
WORKDIR /usr/local
ENV GO_VERSION=1.12
ENV GO111MODULE=on
ENV GOPATH /go
RUN wget -q https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz && \
tar -xzf go${GO_VERSION}.linux-amd64.tar.gz && rm go${GO_VERSION}.linux-amd64.tar.gz && mkdir -p ${GOPATH}

WORKDIR /go/src/agones.dev/agones
ENV PATH /usr/local/go/bin:/go/bin:$PATH

RUN curl -sL https://deb.nodesource.com/setup_11.x | bash - && \
apt-get install -y nodejs

# code generation scripts
COPY *.sh /root/
RUN chmod +x /root/*.sh
25 changes: 25 additions & 0 deletions build/build-sdk-conformance/jstest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash

# Copyright 2019 Google Inc. 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.
set -ex

cd /go/src/agones.dev/agones/test/sdk
./sdk --test="" --sdk="nodejs"
cd /go/src/agones.dev/agones/test/sdk/bin/nodejs
npm install --cache /tmp/empty-cache
npm rebuild

cd /go/src/agones.dev/agones/test/sdk
./sdk --verify=true --sdk nodejs
26 changes: 26 additions & 0 deletions build/build-sdk-conformance/sidecar.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

# Copyright 2019 Google Inc. 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.

set -ex

GO111MODULE=off
cd /go/src/agones.dev/agones/cmd/sdk-server
go build
cd /go/src/agones.dev/agones/test/sdk
rm -rf ./bin
mkdir -p ./bin
mv /go/src/agones.dev/agones/cmd/sdk-server/sdk-server ./bin
go build
31 changes: 31 additions & 0 deletions build/build-sdk-conformance/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

# Copyright 2019 Google Inc. 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.

set -ex
GO111MODULE=off

cd /go/src/agones.dev/agones/test/sdk
./sdk --test=""
cd ./bin/golang/
dirs=($(find . -mindepth 1 -type d))
for dir in "${dirs[@]}"; do
cd "$dir"
go build
echo $PWD
cd -
done
cd /go/src/agones.dev/agones/test/sdk
./sdk --verify=true
12 changes: 12 additions & 0 deletions build/includes/sdk.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ build_sdk_base_remote_tag = $(REGISTRY)/$(build_sdk_base_tag)
build_sdk_prefix = agones-build-sdk-
grpc_release_tag = v1.16.1
sdk_build_folder = build-sdk-images/
sdk_build_conformance-folder = build-sdk-conformance/
SDK_FOLDER ?= go
COMMAND ?= gen

Expand Down Expand Up @@ -108,3 +109,14 @@ ensure-build-sdk-image-base:
# create the build image sdk if it doesn't exist
ensure-build-sdk-image:
$(MAKE) build-build-sdk-image SDK_FOLDER=$(SDK_FOLDER)

build-conformance-tests:
cd $(sdk_build_conformance-folder); \
docker build --tag=conformance:$(build_version) ./ $(DOCKER_BUILD_ARGS)
docker run --rm $(common_mounts) -e "VERSION=$(VERSION)" $(DOCKER_RUN_ARGS) conformance:$(build_version) /root/sidecar.sh

run-conformance-tests:
docker run --rm $(common_mounts) -e "VERSION=$(VERSION)" $(DOCKER_RUN_ARGS) conformance:$(build_version) /root/test.sh

run-conformance-jstests:
docker run --rm $(common_mounts) -e "VERSION=$(VERSION)" $(DOCKER_RUN_ARGS) conformance:$(build_version) /root/jstest.sh
22 changes: 20 additions & 2 deletions cmd/sdk-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"path/filepath"
"strings"
"time"

"agones.dev/agones/pkg"
"agones.dev/agones/pkg/client/clientset/versioned"
Expand Down Expand Up @@ -51,6 +52,7 @@ const (
localFlag = "local"
fileFlag = "file"
addressFlag = "address"
timeout = "timeout"
)

var (
Expand All @@ -69,6 +71,7 @@ func main() {
logger.WithField("grpcPort", grpcPort).WithField("Address", ctlConf.Address).Fatalf("Could not listen on grpcPort")
}
stop := signals.NewStopChannel()
timedStop := make(chan struct{})
grpcServer := grpc.NewServer()
// don't graceful stop, because if we get a kill signal
// then the gameserver is being shut down, and we no longer
Expand All @@ -89,6 +92,12 @@ func main() {
if err != nil {
logger.WithError(err).Fatal("Could not start local sdk server")
}
if ctlConf.Timeout != 0 {
go func() {
time.Sleep(time.Duration(ctlConf.Timeout) * time.Second)
close(timedStop)
}()
}
} else {
var config *rest.Config
config, err = rest.InClusterConfig()
Expand Down Expand Up @@ -127,7 +136,11 @@ func main() {
go runGrpc(grpcServer, lis)
go runGateway(ctx, grpcEndpoint, mux, httpServer)

<-stop
select {
case <-stop:
case <-timedStop:
}

logger.Info("shutting down sdk server")
}

Expand Down Expand Up @@ -190,22 +203,26 @@ func parseEnvFlags() config {
viper.SetDefault(localFlag, false)
viper.SetDefault(fileFlag, "")
viper.SetDefault(addressFlag, "localhost")
viper.SetDefault(timeout, 0)
pflag.Bool(localFlag, viper.GetBool(localFlag),
"Set this, or LOCAL env, to 'true' to run this binary in local development mode. Defaults to 'false'")
pflag.StringP(fileFlag, "f", viper.GetString(fileFlag), "Set this, or FILE env var to the path of a local yaml or json file that contains your GameServer resoure configuration")
pflag.String(addressFlag, viper.GetString(addressFlag), "The Address to bind the server grpcPort to. Defaults to 'localhost")
pflag.String(addressFlag, viper.GetString(addressFlag), "The Address to bind the server grpcPort to. Defaults to 'localhost'")
pflag.Int(timeout, viper.GetInt(timeout), "Time of execution before close. Useful for tests")
pflag.Parse()

viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
runtime.Must(viper.BindEnv(localFlag))
runtime.Must(viper.BindEnv(gameServerNameEnv))
runtime.Must(viper.BindEnv(podNamespaceEnv))
runtime.Must(viper.BindEnv(timeout))
runtime.Must(viper.BindPFlags(pflag.CommandLine))

return config{
IsLocal: viper.GetBool(localFlag),
Address: viper.GetString(addressFlag),
LocalFile: viper.GetString(fileFlag),
Timeout: viper.GetInt(timeout),
}
}

Expand All @@ -214,4 +231,5 @@ type config struct {
Address string
IsLocal bool
LocalFile string
Timeout int
}
28 changes: 28 additions & 0 deletions test/sdk/harness/testGetGameserver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2019 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.

steps:
- init
- ready
- getGameServer
- watchGameServer
- setlabel
- setannotation
- cleanup
expected:
- Ready
- getting GameServer details
- connected to watch GameServer
- Setting label
- Setting annotation
24 changes: 24 additions & 0 deletions test/sdk/harness/testHealth.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2019 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.

steps:
- init
- ready
- health
- shutdown
- cleanup
expected:
- Ready
- Health
- Shutdown
26 changes: 26 additions & 0 deletions test/sdk/harness/testReady.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2019 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.

steps:
- init
- ready
- allocate
- setlabel
- setannotation
- cleanup
expected:
- Ready
- Allocate
- Setting label
- Setting annotation
Loading