fix(multiplayer): fence provider allocation results

This commit is contained in:
Josh Creek
2026-09-03 00:19:03 +01:00
parent a15368ed29
commit bef71e1dcf
5 changed files with 87 additions and 12 deletions
+15
View File
@@ -93,6 +93,21 @@ func TestWorkerRecoversProviderAllocationBeforeIssuingSecondAllocation(t *testin
}
}
func TestWorkerBindsCanonicalRecordedRecovery(t *testing.T) {
now := time.Unix(1_000, 0)
request := domain.AllocationRequest{AllocationID: "allocation-1", MatchID: "match-1", Region: "EU", Build: "build-1", Protocol: 1, Transport: "enet"}
providerAllocation := 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}
canonical := providerAllocation
canonical.AllocatedAt = now
claims := &matchClaimSpy{request: request, found: true}
provider := &recoverableProviderSpy{recovered: agones.AllocatedServer{Allocation: providerAllocation, Endpoint: "127.0.0.1:31001"}, found: true}
worker := Worker{Claims: claims, Service: Service{Provider: provider, Durable: &durableSpy{result: canonical}, Now: func() time.Time { return now }}, Now: func() time.Time { return now }}
processed, err := worker.RunOnce(context.Background())
if err != nil || !processed || claims.bound != canonical {
t.Fatalf("processed=%t err=%v bound=%+v, want %+v", processed, err, claims.bound, canonical)
}
}
func TestWorkerRejectsRecoveredAllocationForDifferentCompatibility(t *testing.T) {
request := domain.AllocationRequest{AllocationID: "allocation-1", MatchID: "match-1", Region: "EU", Build: "build-1", Protocol: 1, Transport: "enet"}
claims := &matchClaimSpy{request: request, found: true}