mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-14 07:22:05 +00:00
feat: add serializable matchmaking store boundary
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRetryableRecognisesPostgresSerializationAndDeadlockErrors(t *testing.T) {
|
||||
for _, message := range []string{"pq: 40001 serialization_failure", "ERROR: deadlock detected (40P01)"} {
|
||||
if !retryable(errors.New(message)) {
|
||||
t.Fatalf("not retryable: %q", message)
|
||||
}
|
||||
}
|
||||
for _, message := range []string{"duplicate key value violates unique constraint", "invalid input syntax"} {
|
||||
if retryable(errors.New(message)) {
|
||||
t.Fatalf("incorrectly retryable: %q", message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestClaimSQLContainsDurableOwnershipFences(t *testing.T) {
|
||||
for _, fragment := range []string{"FOR UPDATE SKIP LOCKED", "state = 'QUEUED'", "proposal_participants", "revision = revision + 1"} {
|
||||
if !containsAnySQL(fragment) {
|
||||
t.Fatalf("claim boundary missing %q", fragment)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func containsAnySQL(fragment string) bool {
|
||||
return index(CandidateClaimSQL, fragment) >= 0 || index(ProposalParticipantInsertSQL, fragment) >= 0 || index(QueueTicketProposeSQL, fragment) >= 0
|
||||
}
|
||||
|
||||
func index(s, fragment string) int {
|
||||
for i := 0; i+len(fragment) <= len(s); i++ {
|
||||
if s[i:i+len(fragment)] == fragment {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
Reference in New Issue
Block a user