mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 20:43:43 +00:00
41 lines
1.2 KiB
Go
41 lines
1.2 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'", "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
|
|
}
|