mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-14 01:42:30 +00:00
fix: bind queue candidates to their owner
This commit is contained in:
@@ -62,7 +62,7 @@ func (q *Queue) Create(playerID, ticketID, idempotencyKey string, candidate Cand
|
||||
}
|
||||
return prior.ticket, nil
|
||||
}
|
||||
if idempotencyKey == "" || playerID == "" || ticketID == "" || candidate.TicketID != ticketID {
|
||||
if idempotencyKey == "" || playerID == "" || ticketID == "" || candidate.TicketID != ticketID || candidate.PlayerID != playerID {
|
||||
return QueueTicket{}, fmt.Errorf("%w: invalid queue create", ErrConflict)
|
||||
}
|
||||
if _, ok := q.byPlayer[playerID]; ok {
|
||||
|
||||
@@ -79,6 +79,20 @@ func TestQueueCreateIdempotencyIncludesCandidatePayload(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueueCreateRejectsCandidateOwnedByAnotherPlayer(t *testing.T) {
|
||||
q := NewQueue()
|
||||
now := time.Unix(1000, 0)
|
||||
_, err := q.Create("player-a", "ticket-a", "create-key-123456", Candidate{
|
||||
TicketID: "ticket-a", PlayerID: "player-b", EnqueuedAt: now,
|
||||
}, now)
|
||||
if !errors.Is(err, ErrConflict) {
|
||||
t.Fatalf("mismatched candidate owner error = %v", err)
|
||||
}
|
||||
if got := q.Candidates(now); len(got) != 0 {
|
||||
t.Fatalf("mismatched candidate was stored: %+v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueueConcurrentCreateKeepsOneActiveTicketPerPlayer(t *testing.T) {
|
||||
q := NewQueue()
|
||||
now := time.Unix(1000, 0)
|
||||
|
||||
Reference in New Issue
Block a user