Files
CosmicClash/server/store/result_sql_test.go
T

35 lines
1.2 KiB
Go

package store
import "testing"
func TestResultSQLPreservesReceiptConflictAndAtomicCommitBoundaries(t *testing.T) {
checks := map[string][]string{
ResultReceiptInsertSQL: {"ON CONFLICT DO NOTHING", "payload_digest", "integrity_state"},
ResultReceiptSelectSQL: {"FOR UPDATE", "committed_at"},
ResultCommitLockSQL: {"server_id = $2", "FOR UPDATE"},
ResultMatchCompleteSQL: {"state = 'RESULT_PENDING'", "revision = revision + 1"},
ResultReceiptCommitSQL: {"COALESCE(committed_at", "committed_at"},
ResultOutboxSQL: {"match_completed", "aggregate_id", "revision"},
RatingLockSQL: {"ORDER BY player_id", "FOR UPDATE"},
MatchParticipantRatingsSQL: {"match_participants", "JOIN ratings", "ORDER BY mp.player_id"},
RatingValuesSQL: {"player_id = ANY($1)", "ORDER BY player_id"},
RatingUpdateSQL: {"ranked_games = ranked_games + $5", "revision = revision + 1"},
}
for query, fragments := range checks {
for _, fragment := range fragments {
if !contains(query, fragment) {
t.Fatalf("query %q missing %q", query, fragment)
}
}
}
}
func contains(value, fragment string) bool {
for i := 0; i+len(fragment) <= len(value); i++ {
if value[i:i+len(fragment)] == fragment {
return true
}
}
return false
}