mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 08:23:45 +00:00
fix(multiplayer): bind allocation to accepted proposal
This commit is contained in:
@@ -166,6 +166,36 @@ func TestServiceAllocatesOnlyUnanimouslyAcceptedMatchingProposal(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestServiceRejectsAllocationRequestThatDoesNotMatchAcceptedProposal(t *testing.T) {
|
||||
proposal := domain.Proposal{
|
||||
ProposalID: "proposal-ranked", Playlist: domain.Ranked, State: domain.Accepted,
|
||||
Region: "EU", Protocol: 1, ArenaPath: "res://scenes/arena_01.tscn",
|
||||
Participants: []domain.ProposalParticipant{
|
||||
{PlayerID: "player-a", Response: domain.AcceptedResponse}, {PlayerID: "player-b", Response: domain.AcceptedResponse},
|
||||
{PlayerID: "player-c", Response: domain.AcceptedResponse}, {PlayerID: "player-d", Response: domain.AcceptedResponse},
|
||||
{PlayerID: "player-e", Response: domain.AcceptedResponse}, {PlayerID: "player-f", Response: domain.AcceptedResponse},
|
||||
},
|
||||
}
|
||||
provider := &providerSpy{}
|
||||
service := Service{Provider: provider, Durable: &durableSpy{}, Now: func() time.Time { return time.Unix(1000, 0) }}
|
||||
request := domain.AllocationRequest{AllocationID: "a", MatchID: "m", Playlist: domain.Ranked, Region: "EU", Build: "b", Protocol: 1, ArenaPath: proposal.ArenaPath, Transport: "enet"}
|
||||
for name, mutate := range map[string]func(*domain.AllocationRequest){
|
||||
"playlist": func(r *domain.AllocationRequest) { r.Playlist = domain.Casual },
|
||||
"region": func(r *domain.AllocationRequest) { r.Region = "NA" },
|
||||
"protocol": func(r *domain.AllocationRequest) { r.Protocol = 2 },
|
||||
"arena": func(r *domain.AllocationRequest) { r.ArenaPath = "res://scenes/arena_02.tscn" },
|
||||
} {
|
||||
candidate := request
|
||||
mutate(&candidate)
|
||||
if _, err := service.AllocateAcceptedProposal(context.Background(), proposal, candidate, domain.Ranked, map[string]string{"region": "EU"}); err == nil {
|
||||
t.Fatalf("%s mismatch was accepted", name)
|
||||
}
|
||||
}
|
||||
if provider.calls != 0 {
|
||||
t.Fatalf("provider calls=%d, want 0", provider.calls)
|
||||
}
|
||||
}
|
||||
|
||||
func TestServicePublishesRosterOnlyForAllocatedAssignment(t *testing.T) {
|
||||
roster := &rosterSpy{}
|
||||
service := Service{Roster: roster}
|
||||
|
||||
Reference in New Issue
Block a user