mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
test: verify offline matchmaking pipeline
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package testkit
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cosmic-clash/cosmic-clash/server/domain"
|
||||
)
|
||||
|
||||
func TestOfflineMatchmakingPipelineReachesDurableResult(t *testing.T) {
|
||||
now := time.Unix(1000, 0)
|
||||
queue := domain.NewQueue()
|
||||
for i := 0; i < 6; i++ {
|
||||
playerID := string(rune('a' + i))
|
||||
ticketID := "ticket-" + playerID
|
||||
candidate := domain.Candidate{TicketID: ticketID, PlayerID: playerID, Rating: 1500 + float64(i), EnqueuedAt: now, PredictedRTT: map[string]float64{"EU": 30}}
|
||||
if _, err := queue.Create(playerID, ticketID, "create-key-"+playerID+"-123456", candidate, now); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
candidates := queue.Candidates(now)
|
||||
selection, err := domain.SelectCandidates(candidates[0], candidates[1:], 6, now)
|
||||
if err != nil || len(selection.Players) != 6 || selection.Region != "EU" {
|
||||
t.Fatalf("selection = %+v err=%v", selection, err)
|
||||
}
|
||||
|
||||
playerIDs := make([]string, 0, len(selection.Players))
|
||||
for _, candidate := range selection.Players {
|
||||
playerIDs = append(playerIDs, candidate.PlayerID)
|
||||
}
|
||||
proposal, err := domain.NewProposal("proposal-1234567890123456", domain.Ranked, playerIDs, now)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, participant := range proposal.Participants {
|
||||
proposal, err = proposal.Respond(participant.PlayerID, "accept-"+participant.PlayerID+"-123456", true, proposal.Revision, now)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if proposal.State != domain.Accepted {
|
||||
t.Fatalf("proposal did not accept: %+v", proposal)
|
||||
}
|
||||
|
||||
allocator, err := domain.NewAllocator([]domain.ReadyServer{{ServerID: "server-1", Region: "EU", Build: "build-1", Protocol: 1, Transport: "enet", State: domain.ServerReady}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
allocation, err := allocator.Allocate(domain.AllocationRequest{AllocationID: "allocation-1234567890123456", MatchID: "match-1234567890123456", Region: "EU", Build: "build-1", Protocol: 1, Transport: "enet"}, now)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
manifest := domain.AllocationManifest{AllocationID: allocation.AllocationID, MatchID: allocation.MatchID, ServerID: allocation.ServerID, Region: allocation.Region, Build: allocation.Build, Protocol: allocation.Protocol, Transport: allocation.Transport, RosterDigest: "roster-digest"}
|
||||
digest := domain.ManifestDigest(manifest)
|
||||
assignment, err := domain.VerifyAssignment(allocation, manifest, "127.0.0.1:31001", digest[:], func(_, signature []byte) bool { return string(signature) == string(digest[:]) })
|
||||
if err != nil || assignment.Endpoint == "" {
|
||||
t.Fatalf("assignment = %+v err=%v", assignment, err)
|
||||
}
|
||||
|
||||
store, err := domain.NewResultStore(domain.WorkloadBinding{Issuer: "issuer", Audience: "audience", Namespace: "games", ServiceAcct: "match-server", PodUID: "pod-1", GameServerUID: "gs-1", MatchID: allocation.MatchID, ServerID: allocation.ServerID})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
result := domain.MatchResult{MatchID: allocation.MatchID, ServerID: allocation.ServerID, ResultNonce: "result-nonce-123456", Team0Score: 3, Team1Score: 2, IntegrityState: domain.IntegrityCertified}
|
||||
receipt, created, err := store.Submit("result-1234567890123456", result, domain.WorkloadBinding{Issuer: "issuer", Audience: "audience", Namespace: "games", ServiceAcct: "match-server", PodUID: "pod-1", GameServerUID: "gs-1", MatchID: allocation.MatchID, ServerID: allocation.ServerID}, now)
|
||||
if err != nil || !created || !domain.RatingEligible(receipt) {
|
||||
t.Fatalf("receipt = %+v created=%v err=%v", receipt, created, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user