fix(multiplayer): fence recovered arena identity

This commit is contained in:
Josh Creek
2026-09-01 21:21:10 +01:00
parent 701d7a9a2e
commit 3eb47bb9d3
3 changed files with 14 additions and 2 deletions
+1 -1
View File
@@ -80,7 +80,7 @@ func (w Worker) RunOnce(ctx context.Context) (bool, error) {
func validateRecoveredAllocation(request domain.AllocationRequest, result agones.AllocatedServer) error {
allocation := result.Allocation
if result.Endpoint == "" || allocation.State != domain.ServerAllocated || allocation.AllocationID != request.AllocationID || allocation.MatchID != request.MatchID || allocation.ServerID == "" || allocation.Region != request.Region || allocation.Build != request.Build || allocation.Protocol != request.Protocol || allocation.Transport != request.Transport {
if result.Endpoint == "" || allocation.State != domain.ServerAllocated || allocation.AllocationID != request.AllocationID || allocation.MatchID != request.MatchID || allocation.ServerID == "" || allocation.Region != request.Region || allocation.Build != request.Build || allocation.Protocol != request.Protocol || allocation.Transport != request.Transport || allocation.ArenaPath != request.ArenaPath {
return fmt.Errorf("recovered allocation does not match request")
}
return nil
+12
View File
@@ -105,6 +105,18 @@ func TestWorkerRejectsRecoveredAllocationForDifferentCompatibility(t *testing.T)
}
}
func TestWorkerRejectsRecoveredAllocationForDifferentArena(t *testing.T) {
request := domain.AllocationRequest{AllocationID: "allocation-1", MatchID: "match-1", ArenaPath: "res://scenes/arena_01.tscn", Region: "EU", Build: "build-1", Protocol: 1, Transport: "enet"}
claims := &matchClaimSpy{request: request, found: true}
provider := &recoverableProviderSpy{recovered: agones.AllocatedServer{Allocation: domain.Allocation{AllocationID: request.AllocationID, MatchID: request.MatchID, ServerID: "server-1", ArenaPath: "res://scenes/arena_02.tscn", Region: request.Region, Build: request.Build, Protocol: request.Protocol, Transport: request.Transport, State: domain.ServerAllocated}, Endpoint: "127.0.0.1:31001"}, found: true}
durable := &durableSpy{}
worker := Worker{Claims: claims, Service: Service{Provider: provider, Durable: durable, Now: func() time.Time { return time.Unix(1_000, 0) }}, Now: func() time.Time { return time.Unix(1_000, 0) }}
processed, err := worker.RunOnce(context.Background())
if err == nil || !processed || durable.calls != 0 || claims.bound != (domain.Allocation{}) {
t.Fatalf("processed=%t err=%v durable_calls=%d bound=%+v", processed, err, durable.calls, claims.bound)
}
}
func TestWorkerDoesNothingWhenNoDurableMatchIsAvailable(t *testing.T) {
claims := &matchClaimSpy{}
worker := Worker{Claims: claims, Now: func() time.Time { return time.Unix(1_000, 0) }}