Skip to content

Commit

Permalink
Fix Local SDK nil Players with test (#1572)
Browse files Browse the repository at this point in the history
* Fix Local SDK nil Players with test

There was a situation when additional call in testMode leads to
SegFault.
  • Loading branch information
aLekSer authored May 19, 2020
1 parent 3f1233a commit 9dbb6bc
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 107 deletions.
3 changes: 2 additions & 1 deletion build/includes/sdk.mk
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,10 @@ ensure-build-sdk-image:
# SDK client test against it. Useful for test development
run-sdk-conformance-local: TIMEOUT ?= 30
run-sdk-conformance-local: TESTS ?= ready,allocate,setlabel,setannotation,gameserver,health,shutdown,watch,reserve
run-sdk-conformance-local: FEATURE_GATES ?=
run-sdk-conformance-local: ensure-agones-sdk-image
docker run -e "ADDRESS=" -p 9357:9357 -p 9358:9358 \
-e "TEST=$(TESTS)" -e "TIMEOUT=$(TIMEOUT)" $(sidecar_tag)
-e "TEST=$(TESTS)" -e "TIMEOUT=$(TIMEOUT)" -e "FEATURE_GATES=$(FEATURE_GATES)" $(sidecar_tag)

# Run SDK conformance test, previously built, for a specific SDK_FOLDER
# Sleeps the start of the sidecar to test that the SDK blocks on connection correctly
Expand Down
17 changes: 14 additions & 3 deletions pkg/sdkserver/localsdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ var (
_ sdk.SDKServer = &LocalSDKServer{}
_ alpha.SDKServer = &LocalSDKServer{}
_ beta.SDKServer = &LocalSDKServer{}
)

defaultGs = &sdk.GameServer{
func defaultGs() *sdk.GameServer {
return &sdk.GameServer{
ObjectMeta: &sdk.GameServer_ObjectMeta{
Name: "local",
Namespace: "default",
Expand All @@ -66,7 +68,7 @@ var (
Ports: []*sdk.GameServer_Status_Port{{Name: "default", Port: 7777}},
},
}
)
}

// LocalSDKServer type is the SDKServer implementation for when the sidecar
// is being run for local development, and doesn't connect to the
Expand All @@ -91,7 +93,7 @@ type LocalSDKServer struct {
func NewLocalSDKServer(filePath string) (*LocalSDKServer, error) {
l := &LocalSDKServer{
gsMutex: sync.RWMutex{},
gs: defaultGs,
gs: defaultGs(),
update: make(chan struct{}),
updateObservers: sync.Map{},
testMutex: sync.Mutex{},
Expand Down Expand Up @@ -134,6 +136,9 @@ func NewLocalSDKServer(filePath string) (*LocalSDKServer, error) {
l.logger.WithError(err).WithField("filePath", filePath).Error("error adding watcher")
}
}
if runtime.FeatureEnabled(runtime.FeaturePlayerTracking) && l.gs.Status.Players == nil {
l.gs.Status.Players = &sdk.GameServer_Status_PlayerStatus{}
}

go func() {
for value := range l.update {
Expand Down Expand Up @@ -197,8 +202,14 @@ func (l *LocalSDKServer) recordRequestWithValue(request string, value string, ob
case "UID":
fieldVal = l.gs.ObjectMeta.Uid
case "PlayerCapacity":
if !runtime.FeatureEnabled(runtime.FeaturePlayerTracking) {
return
}
fieldVal = strconv.FormatInt(l.gs.Status.Players.Capacity, 10)
case "PlayerIDs":
if !runtime.FeatureEnabled(runtime.FeaturePlayerTracking) {
return
}
fieldVal = strings.Join(l.gs.Status.Players.Ids, ",")
default:
l.logger.Error("unexpected Field to compare")
Expand Down
Loading

0 comments on commit 9dbb6bc

Please sign in to comment.