mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 08:23:45 +00:00
test: verify offline matchmaking pipeline
This commit is contained in:
@@ -147,7 +147,15 @@ func (p *Proposal) allAccepted() bool {
|
||||
func (p *Proposal) copy() Proposal {
|
||||
clone := *p
|
||||
clone.Participants = append([]ProposalParticipant(nil), p.Participants...)
|
||||
clone.idempotent = nil
|
||||
if p.idempotent != nil {
|
||||
clone.idempotent = make(map[string]proposalMutation, len(p.idempotent))
|
||||
for key, mutation := range p.idempotent {
|
||||
prior := mutation.proposal
|
||||
prior.Participants = append([]ProposalParticipant(nil), prior.Participants...)
|
||||
prior.idempotent = nil
|
||||
clone.idempotent[key] = proposalMutation{digest: mutation.digest, proposal: prior}
|
||||
}
|
||||
}
|
||||
return clone
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,23 @@ func TestProposalResponseReplayIsStableAndPayloadReuseConflicts(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestReturnedProposalRetainsIdempotencyStateForChainedResponses(t *testing.T) {
|
||||
now := time.Unix(1000, 0)
|
||||
p, err := NewProposal("proposal-123456789", Ranked, []string{"a", "b", "c", "d", "e", "f"}, now)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, playerID := range []string{"a", "b", "c", "d", "e", "f"} {
|
||||
p, err = p.Respond(playerID, "accept-"+playerID+"-123456", true, p.Revision, now)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if p.State != Accepted || p.Revision != 6 {
|
||||
t.Fatalf("chained responses = %+v", p)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProposalExpiryTimesOutPendingParticipantsAndClosesRace(t *testing.T) {
|
||||
now := time.Unix(1000, 0)
|
||||
p, err := NewProposal("proposal-123456789", Ranked, []string{"a", "b", "c", "d", "e", "f"}, now)
|
||||
|
||||
Reference in New Issue
Block a user