Skip to content

Commit

Permalink
Adds SDK Server List Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
igooch committed Oct 25, 2023
1 parent f6f948c commit 0439937
Show file tree
Hide file tree
Showing 2 changed files with 417 additions and 9 deletions.
21 changes: 12 additions & 9 deletions pkg/sdkserver/sdkserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1055,14 +1055,14 @@ func (s *SDKServer) UpdateList(ctx context.Context, in *alpha.UpdateListRequest)
name := in.List.Name
s.logger.WithField("name", name).Debug("Update List -- Currently only used for Updating Capacity")

s.gsUpdateMutex.Lock()
defer s.gsUpdateMutex.Unlock()

gs, err := s.gameServer()
if err != nil {
return nil, err
}

s.gsUpdateMutex.Lock()
defer s.gsUpdateMutex.Unlock()

// TODO: Pull in variable Max Capacity from CRD instead of hard-coded number here.
if in.List.Capacity < 0 || in.List.Capacity > 1000 {
return nil, errors.Errorf("out of range. Capacity must be within range [0,1000]. Found Capacity: %d", in.List.Capacity)
Expand Down Expand Up @@ -1091,14 +1091,14 @@ func (s *SDKServer) AddListValue(ctx context.Context, in *alpha.AddListValueRequ
}
s.logger.WithField("name", in.Name).Debug("Add List Value")

s.gsUpdateMutex.Lock()
defer s.gsUpdateMutex.Unlock()

gs, err := s.gameServer()
if err != nil {
return nil, err
}

s.gsUpdateMutex.Lock()
defer s.gsUpdateMutex.Unlock()

if list, ok := gs.Status.Lists[in.Name]; ok {
batchList := s.gsListUpdates[in.Name]
// Verify room to add another value
Expand Down Expand Up @@ -1147,14 +1147,14 @@ func (s *SDKServer) RemoveListValue(ctx context.Context, in *alpha.RemoveListVal

s.logger.WithField("name", in.Name).Debug("Remove List Value")

s.gsUpdateMutex.Lock()
defer s.gsUpdateMutex.Unlock()

gs, err := s.gameServer()
if err != nil {
return nil, err
}

s.gsUpdateMutex.Lock()
defer s.gsUpdateMutex.Unlock()

if list, ok := gs.Status.Lists[in.Name]; ok {
// Verify value exists in the list
for _, val := range list.Values {
Expand All @@ -1163,6 +1163,9 @@ func (s *SDKServer) RemoveListValue(ctx context.Context, in *alpha.RemoveListVal
}
// Add value to remove to gsListUpdates map.
batchList := s.gsListUpdates[in.Name]
if batchList.valuesToDelete == nil {
batchList.valuesToDelete = map[string]bool{}
}
batchList.valuesToDelete[in.Value] = true
s.gsListUpdates[in.Name] = batchList
// Queue up the Update for later batch processing by updateLists.
Expand Down
Loading

0 comments on commit 0439937

Please sign in to comment.