Workers claim with SKIP LOCKED, heartbeat by token, and ack/fail only when the fencing token still matches. Shadow scans without acking live deliveries. Co-authored-by: Cursor <cursoragent@cursor.com>
40 lines
889 B
Go
40 lines
889 B
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")
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|