mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
fix(multiplayer): recover recorded allocations
This commit is contained in:
@@ -12,11 +12,17 @@ import (
|
||||
)
|
||||
|
||||
type matchClaimSpy struct {
|
||||
request domain.AllocationRequest
|
||||
found bool
|
||||
err error
|
||||
bound domain.Allocation
|
||||
bindErr error
|
||||
request domain.AllocationRequest
|
||||
found bool
|
||||
err error
|
||||
recorded domain.Allocation
|
||||
recordErr error
|
||||
bound domain.Allocation
|
||||
bindErr error
|
||||
}
|
||||
|
||||
func (s *matchClaimSpy) FindProviderAllocation(_ context.Context, _ domain.AllocationRequest) (domain.Allocation, bool, error) {
|
||||
return s.recorded, s.recorded.AllocationID != "", s.recordErr
|
||||
}
|
||||
|
||||
func (s *matchClaimSpy) ClaimAllocatingMatch(_ context.Context, _ time.Time) (domain.AllocationRequest, bool, error) {
|
||||
@@ -51,6 +57,18 @@ func TestWorkerRetainsClaimWhenProviderOutcomeIsAmbiguous(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkerRecoversDurableProviderAllocationWithoutCallingProvider(t *testing.T) {
|
||||
request := domain.AllocationRequest{AllocationID: "allocation-1", MatchID: "match-1", Region: "EU", Build: "build-1", Protocol: 1, Transport: "enet"}
|
||||
recorded := domain.Allocation{AllocationID: request.AllocationID, MatchID: request.MatchID, ServerID: "server-1", Region: request.Region, Build: request.Build, Protocol: request.Protocol, Transport: request.Transport, State: domain.ServerAllocated}
|
||||
claims := &matchClaimSpy{request: request, found: true, recorded: recorded}
|
||||
provider := &providerSpy{}
|
||||
worker := Worker{Claims: claims, Service: Service{Provider: provider, Durable: &durableSpy{}, 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 || claims.bound != recorded {
|
||||
t.Fatalf("processed=%t err=%v provider=%d bound=%+v", processed, err, provider.calls, claims.bound)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWorkerDoesNothingWhenNoDurableMatchIsAvailable(t *testing.T) {
|
||||
claims := &matchClaimSpy{}
|
||||
worker := Worker{Claims: claims, Now: func() time.Time { return time.Unix(1_000, 0) }}
|
||||
|
||||
Reference in New Issue
Block a user