Files
weichenandCursor 2a666df3c1 fix(events): hold aggregate gaps on production claim
PostgreSQL claim now uses the same next-version rule as MemoryBus, and checkpoints only move forward. A later version cannot be leased while an earlier one is still missing.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-19 09:24:51 +00:00

52 lines
1.4 KiB
Go

package events
import (
"os"
"path/filepath"
"runtime"
"strings"
"testing"
)
func TestClaimSQLUsesSkipLockedOnlyForClaim(t *testing.T) {
if !strings.Contains(claimSQL, "FOR UPDATE OF d SKIP LOCKED") {
t.Fatal("claim must use SKIP LOCKED")
}
if strings.Count(claimSQL, "SKIP LOCKED") != 1 {
t.Fatal("SKIP LOCKED is only for claim")
}
if !strings.Contains(claimSQL, "event_consumer_checkpoints") || !strings.Contains(claimSQL, "e.aggregate_version = 0") {
t.Fatal("claim SQL must hold the same aggregate gap as MemoryBus")
}
}
func TestVersionClaimableMatchesMemoryBusGap(t *testing.T) {
if !VersionClaimable(0, 0) || !VersionClaimable(0, 1) || VersionClaimable(0, 2) {
t.Fatal("head 0 allows unversioned and v1 only")
}
if !VersionClaimable(1, 2) || VersionClaimable(1, 3) {
t.Fatal("head 1 allows v2 and rejects v3")
}
}
func TestSkipLockedAbsentFromInsertSQL(t *testing.T) {
_, file, _, ok := runtime.Caller(0)
if !ok {
t.Fatal("caller")
}
src, err := os.ReadFile(filepath.Join(filepath.Dir(file), "pg.go"))
if err != nil {
t.Fatal(err)
}
if strings.Contains(string(src), "SKIP LOCKED") {
t.Fatal("SKIP LOCKED must not appear in pg.go")
}
}
func TestClaimIDsDisabled(t *testing.T) {
_, err := ClaimIDs(nil, nil, ConsumerNotify, 1)
if err == nil || !strings.Contains(err.Error(), "SELECT-only claim is disabled") {
t.Fatalf("%v", err)
}
}