fix(multiplayer): recover ambiguous agones allocations

This commit is contained in:
Josh Creek
2026-09-01 18:05:43 +01:00
parent b72a7cf843
commit bf396afcaf
6 changed files with 161 additions and 8 deletions
+24
View File
@@ -21,6 +21,17 @@ type matchClaimSpy struct {
bindErr error
}
type recoverableProviderSpy struct {
providerSpy
recovered agones.AllocatedServer
found bool
recoverErr error
}
func (p *recoverableProviderSpy) RecoverAllocation(_ context.Context, _ domain.AllocationRequest, _ time.Time) (agones.AllocatedServer, bool, error) {
return p.recovered, p.found, p.recoverErr
}
func (s *matchClaimSpy) FindProviderAllocation(_ context.Context, _ domain.AllocationRequest) (domain.Allocation, bool, error) {
return s.recorded, s.recorded.AllocationID != "", s.recordErr
}
@@ -69,6 +80,19 @@ func TestWorkerRecoversDurableProviderAllocationWithoutCallingProvider(t *testin
}
}
func TestWorkerRecoversProviderAllocationBeforeIssuingSecondAllocation(t *testing.T) {
request := domain.AllocationRequest{AllocationID: "allocation-1", MatchID: "match-1", Region: "EU", Build: "build-1", Protocol: 1, Transport: "enet"}
recovered := agones.AllocatedServer{Allocation: domain.Allocation{AllocationID: request.AllocationID, MatchID: request.MatchID, ServerID: "server-recovered", Region: request.Region, Build: request.Build, Protocol: request.Protocol, Transport: request.Transport, State: domain.ServerAllocated}, Endpoint: "127.0.0.1:31001"}
claims := &matchClaimSpy{request: request, found: true}
provider := &recoverableProviderSpy{recovered: recovered, 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 || provider.calls != 0 || durable.calls != 1 || claims.bound.ServerID != "server-recovered" {
t.Fatalf("processed=%t err=%v provider_calls=%d durable_calls=%d bound=%+v", processed, err, provider.calls, 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) }}