mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
41 lines
1.4 KiB
Go
41 lines
1.4 KiB
Go
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'", "player_id = $2", "playlist = $3", "proposal_participants", "revision = revision + 1", "INSERT INTO proposals", "ranked_season_rollovers", "ON CONFLICT (player_id, season_id) DO NOTHING"} {
|
|
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 || index(ProposalInsertSQL, fragment) >= 0 || index(SeasonRolloverInsertSQL, 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
|
|
}
|