Skip to content

Commit 85bb01f

Browse files
Robert Baileymarkmandel
authored andcommitted
Add a delay flag to the sdkserver to enable test scenarios where it (agones-dev#1070)
doesn't start up immediately.
1 parent 550a30d commit 85bb01f

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎build/includes/sdk.mk‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,13 @@ run-sdk-conformance-local: ensure-agones-sdk-image
125125
# Sleeps the start of the sidecar to test that the SDK blocks on connection correctly
126126
run-sdk-conformance-no-build: TIMEOUT ?= 30
127127
run-sdk-conformance-no-build: RANDOM := $(shell bash -c 'echo $$RANDOM')
128-
run-sdk-conformance-no-build: DELAY ?= $(shell bash -c "echo $$[ ($(RANDOM) % 5 ) + 1 ]s")
128+
run-sdk-conformance-no-build: DELAY ?= $(shell bash -c "echo $$[ ($(RANDOM) % 5 ) + 1 ]")
129129
run-sdk-conformance-no-build: TESTS ?= ready,allocate,setlabel,setannotation,gameserver,health,shutdown,watch,reserve
130130
run-sdk-conformance-no-build: ensure-agones-sdk-image
131131
run-sdk-conformance-no-build: ensure-build-sdk-image
132132
DOCKER_RUN_ARGS="--network=host $(DOCKER_RUN_ARGS)" COMMAND=sdktest $(MAKE) run-sdk-command & \
133-
sleep $(DELAY) && docker run -p 59357:59357 -e "ADDRESS=" \
134-
-e "TEST=$(TESTS)" -e "TIMEOUT=$(TIMEOUT)" --net=host $(sidecar_tag)
133+
docker run -p 59357:59357 -e "ADDRESS=" -e "TEST=$(TESTS)" -e "TIMEOUT=$(TIMEOUT)" -e "DELAY=$(DELAY)" \
134+
--net=host $(sidecar_tag)
135135

136136
# Run SDK conformance test for a specific SDK_FOLDER
137137
run-sdk-conformance-test:

‎cmd/sdk-server/main.go‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const (
5353
fileFlag = "file"
5454
testFlag = "test"
5555
addressFlag = "address"
56+
delayFlag = "delay"
5657
timeoutFlag = "timeout"
5758
)
5859

@@ -71,6 +72,12 @@ func main() {
7172
if err != nil {
7273
logger.WithField("grpcPort", grpcPort).WithField("Address", ctlConf.Address).Fatalf("Could not listen on grpcPort")
7374
}
75+
76+
if ctlConf.Delay > 0 {
77+
logger.Infof("Waiting %d seconds before starting", ctlConf.Delay)
78+
time.Sleep(time.Duration(ctlConf.Delay) * time.Second)
79+
}
80+
7481
stop := signals.NewStopChannel()
7582
timedStop := make(chan struct{})
7683
grpcServer := grpc.NewServer()
@@ -232,12 +239,14 @@ func parseEnvFlags() config {
232239
viper.SetDefault(fileFlag, "")
233240
viper.SetDefault(testFlag, "")
234241
viper.SetDefault(addressFlag, "localhost")
242+
viper.SetDefault(delayFlag, 0)
235243
viper.SetDefault(timeoutFlag, 0)
236244
pflag.Bool(localFlag, viper.GetBool(localFlag),
237245
"Set this, or LOCAL env, to 'true' to run this binary in local development mode. Defaults to 'false'")
238246
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")
239247
pflag.String(addressFlag, viper.GetString(addressFlag), "The Address to bind the server grpcPort to. Defaults to 'localhost'")
240-
pflag.Int(timeoutFlag, viper.GetInt(timeoutFlag), "Time of execution before close. Useful for tests")
248+
pflag.Int(delayFlag, viper.GetInt(delayFlag), "Time to delay (in seconds) before starting to execute main. Useful for tests")
249+
pflag.Int(timeoutFlag, viper.GetInt(timeoutFlag), "Time of execution (in seconds) before close. Useful for tests")
241250
pflag.String(testFlag, viper.GetString(testFlag), "List functions which shoud be called during the SDK Conformance test run.")
242251
pflag.Parse()
243252

@@ -247,13 +256,15 @@ func parseEnvFlags() config {
247256
runtime.Must(viper.BindEnv(testFlag))
248257
runtime.Must(viper.BindEnv(gameServerNameEnv))
249258
runtime.Must(viper.BindEnv(podNamespaceEnv))
259+
runtime.Must(viper.BindEnv(delayFlag))
250260
runtime.Must(viper.BindEnv(timeoutFlag))
251261
runtime.Must(viper.BindPFlags(pflag.CommandLine))
252262

253263
return config{
254264
IsLocal: viper.GetBool(localFlag),
255265
Address: viper.GetString(addressFlag),
256266
LocalFile: viper.GetString(fileFlag),
267+
Delay: viper.GetInt(delayFlag),
257268
Timeout: viper.GetInt(timeoutFlag),
258269
Test: viper.GetString(testFlag),
259270
}
@@ -264,6 +275,7 @@ type config struct {
264275
Address string
265276
IsLocal bool
266277
LocalFile string
278+
Delay int
267279
Timeout int
268280
Test string
269281
}

0 commit comments

Comments
 (0)