Skip to content

Commit

Permalink
Add Shutdown Delay Seconds to the containers (#4030)
Browse files Browse the repository at this point in the history
  • Loading branch information
igooch authored Nov 7, 2024
1 parent 6e6fe5d commit 6d36d20
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test/sdk/go/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ project_path := $(dir $(mkfile_path))
root_path = $(realpath $(project_path)/)
# Because go mod init in the Dockerfile installs the most recently released version of Agones, this
# will need to be built and pushed post-release. During DEV it will be built at DEV - 1.
release_version = 1.43.0
release_version = 1.44.0
server_tag := $(REGISTRY)/sdk-client-test:$(release_version)

# _____ _
Expand Down
26 changes: 24 additions & 2 deletions test/sdk/go/sdk-client-test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package main

import (
"log"
"os"
"strconv"
"strings"
"time"
Expand All @@ -38,6 +39,24 @@ func main() {
runtime.Must(runtime.FeaturesBindEnv())
runtime.Must(runtime.ParseFeaturesFromEnv())

// Use to delays to prevent Game Servers from churning too quickly on a running cluster.
shutdownDelaySec := 0
gracefulTerminationDelaySec := 0
if sds := os.Getenv("SHUTDOWN_DELAY_SECONDS"); sds != "" {
sec, err := strconv.Atoi(sds)
if err != nil {
log.Fatalf("Could not parse SHUTDOWN_DELAY_SECONDS: %v", err)
}
shutdownDelaySec = sec
}
if gtds := os.Getenv("GRACEFUL_TERMINATION_DELAY_SECONDS"); gtds != "" {
sec, err := strconv.Atoi(gtds)
if err != nil {
log.Fatalf("Could not parse GRACEFUL_TERMINATION_DELAY_SECONDS: %v", err)
}
gracefulTerminationDelaySec = sec
}

log.SetFlags(log.Lshortfile)
log.Println("Client is starting")
log.Printf("Feature Flags: %s\n", runtime.EncodeFeatures())
Expand Down Expand Up @@ -105,13 +124,16 @@ func main() {
testLists(sdk)
}

// Delay before shutdown to prevent Game Servers from churning too quickly on a running cluster
time.Sleep(8 * time.Second)
log.Printf("Waiting %d seconds before shutting down game server", shutdownDelaySec)
time.Sleep(time.Duration(shutdownDelaySec) * time.Second)

err = sdk.Shutdown()
if err != nil {
log.Fatalf("Could not shutdown GameServer: %s", err)
}

log.Printf("Waiting %d seconds before exiting", gracefulTerminationDelaySec)
time.Sleep(time.Duration(gracefulTerminationDelaySec) * time.Second)
}

func testPlayerTracking(sdk *goSdk.SDK) {
Expand Down

0 comments on commit 6d36d20

Please sign in to comment.