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 a delay flag to the sdkserver #1070

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions build/includes/sdk.mk
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ run-sdk-conformance-local: ensure-agones-sdk-image
# Sleeps the start of the sidecar to test that the SDK blocks on connection correctly
run-sdk-conformance-no-build: TIMEOUT ?= 30
run-sdk-conformance-no-build: RANDOM := $(shell bash -c 'echo $$RANDOM')
run-sdk-conformance-no-build: DELAY ?= $(shell bash -c "echo $$[ ($(RANDOM) % 5 ) + 1 ]s")
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: ensure-agones-sdk-image
run-sdk-conformance-no-build: ensure-build-sdk-image
DOCKER_RUN_ARGS="--network=host $(DOCKER_RUN_ARGS)" COMMAND=sdktest $(MAKE) run-sdk-command & \
sleep $(DELAY) && docker run -p 59357:59357 -e "ADDRESS=" \
-e "TEST=$(TESTS)" -e "TIMEOUT=$(TIMEOUT)" --net=host $(sidecar_tag)
docker run -p 59357:59357 -e "ADDRESS=" -e "TEST=$(TESTS)" -e "TIMEOUT=$(TIMEOUT)" -e "DELAY=$(DELAY)" \
--net=host $(sidecar_tag)

# Run SDK conformance test for a specific SDK_FOLDER
run-sdk-conformance-test:
Expand Down
14 changes: 13 additions & 1 deletion cmd/sdk-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const (
fileFlag = "file"
testFlag = "test"
addressFlag = "address"
delayFlag = "delay"
timeoutFlag = "timeout"
)

Expand All @@ -71,6 +72,12 @@ func main() {
if err != nil {
logger.WithField("grpcPort", grpcPort).WithField("Address", ctlConf.Address).Fatalf("Could not listen on grpcPort")
}

if ctlConf.Delay > 0 {
logger.Infof("Waiting %d seconds before starting", ctlConf.Delay)
time.Sleep(time.Duration(ctlConf.Delay) * time.Second)
}

stop := signals.NewStopChannel()
timedStop := make(chan struct{})
grpcServer := grpc.NewServer()
Expand Down Expand Up @@ -232,12 +239,14 @@ func parseEnvFlags() config {
viper.SetDefault(fileFlag, "")
viper.SetDefault(testFlag, "")
viper.SetDefault(addressFlag, "localhost")
viper.SetDefault(delayFlag, 0)
viper.SetDefault(timeoutFlag, 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.Int(timeoutFlag, viper.GetInt(timeoutFlag), "Time of execution before close. Useful for tests")
pflag.Int(delayFlag, viper.GetInt(delayFlag), "Time to delay (in seconds) before starting to execute main. Useful for tests")
pflag.Int(timeoutFlag, viper.GetInt(timeoutFlag), "Time of execution (in seconds) before close. Useful for tests")
pflag.String(testFlag, viper.GetString(testFlag), "List functions which shoud be called during the SDK Conformance test run.")
pflag.Parse()

Expand All @@ -247,13 +256,15 @@ func parseEnvFlags() config {
runtime.Must(viper.BindEnv(testFlag))
runtime.Must(viper.BindEnv(gameServerNameEnv))
runtime.Must(viper.BindEnv(podNamespaceEnv))
runtime.Must(viper.BindEnv(delayFlag))
runtime.Must(viper.BindEnv(timeoutFlag))
runtime.Must(viper.BindPFlags(pflag.CommandLine))

return config{
IsLocal: viper.GetBool(localFlag),
Address: viper.GetString(addressFlag),
LocalFile: viper.GetString(fileFlag),
Delay: viper.GetInt(delayFlag),
Timeout: viper.GetInt(timeoutFlag),
Test: viper.GetString(testFlag),
}
Expand All @@ -264,6 +275,7 @@ type config struct {
Address string
IsLocal bool
LocalFile string
Delay int
Timeout int
Test string
}