mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-13 05:02:09 +00:00
feat: add durable allocator claim boundary
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/cosmic-clash/cosmic-clash/server/domain"
|
||||
)
|
||||
|
||||
func TestAllocatorSQLClaimsAndAuditsCompatibleReadyServers(t *testing.T) {
|
||||
for query, fragments := range map[string][]string{
|
||||
RegisterReadyServerSQL: {"game_servers", "ON CONFLICT", "state = 'READY'"},
|
||||
ClaimReadyServerSQL: {"state = 'READY'", "region = $1", "protocol_version = $3", "FOR UPDATE SKIP LOCKED", "ORDER BY server_id"},
|
||||
InsertAllocationSQL: {"allocations", "request_digest", "state", "ALLOCATED"},
|
||||
} {
|
||||
for _, fragment := range fragments {
|
||||
if !contains(query, fragment) {
|
||||
t.Fatalf("query missing %q", fragment)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestClaimAllocationRejectsInvalidRequestsWithoutDatabase(t *testing.T) {
|
||||
_, err := ClaimAllocation(nil, nil, domain.AllocationRequest{AllocationID: "a", MatchID: "m", Region: "EU", Build: "b", Protocol: 1, Transport: "enet"}, time.Unix(1000, 0))
|
||||
if err == nil {
|
||||
t.Fatal("nil database accepted")
|
||||
}
|
||||
if _, err := ClaimAllocation(nil, nil, domain.AllocationRequest{AllocationID: "a", MatchID: "m", Region: "EU", Build: "b", Protocol: 0, Transport: "enet"}, time.Unix(1000, 0)); err != domain.ErrAllocationInput {
|
||||
t.Fatalf("invalid request err=%v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user