3e7fcce0b1
build / build (push) Successful in 1m11s
新增迁移50与每5分钟/手动持久同步,API只读本地;同步失败保留、权限阻断、租约与质量失效原子激活。 保留全量稳定分页/固定列,已存质量批量读取,元数据不反复解压长答案;详情安全Markdown与原文。 已运行整仓 make verify、源与副本隔离PG -race、真实只读源及隔离浏览器。 实际同步2525条;固定窗口640条本地中位1.46秒,对照直接源33.10秒。 停worker、缺源凭据、重启API后仍可查询;未更新8088,未修改生产原问答。
40 lines
1.3 KiB
Go
40 lines
1.3 KiB
Go
package qaopsmirror
|
|
|
|
import (
|
|
"context"
|
|
pg "knowledge-governance/internal/platform/postgres"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestLocalMirrorSchedulerRecoversExhaustedCrash(t *testing.T) {
|
|
p := mirrorFixture(t)
|
|
s := NewStore(p, "fixture-crashed-scheduler")
|
|
q := pg.NewStore(p)
|
|
ctx := context.Background()
|
|
if _, e := q.Claim(ctx, "fixture-crashed-worker", []string{s.SyncJobType()}, time.Now(), time.Minute); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if _, e := p.Exec(ctx, `INSERT INTO qa_ops_mirror_state(tenant_key,next_sync_at) VALUES($1,now()-interval '1 hour')`, s.tenant); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if yes, e := s.EnqueueDue(ctx); e != nil || !yes {
|
|
t.Fatal(e)
|
|
}
|
|
job, e := q.Claim(ctx, "fixture-crashed-worker", []string{s.SyncJobType()}, time.Now(), time.Minute)
|
|
if e != nil || job == nil {
|
|
t.Fatal(e)
|
|
}
|
|
// Model death after claiming the final attempt, before any failure checkpoint.
|
|
if _, e = p.Exec(ctx, `UPDATE jobs SET attempt=max_attempts,lease_until=now()-interval '1 second' WHERE id=$1`, job.ID); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
if _, e = s.EnqueueDue(ctx); e != nil {
|
|
t.Fatal(e)
|
|
}
|
|
state, e := s.GetSyncStatus(ctx)
|
|
if e != nil || state.NextSyncAt == nil || !state.NextSyncAt.After(time.Now()) || state.ErrorCode != "mirror_sync_interrupted" {
|
|
t.Fatal("scheduler replayed an exhausted operation forever instead of persisting a new retry due time", e)
|
|
}
|
|
}
|