删掉会自己开入口、只看服务健康的 FinalizeAfterOperatorRecovery。 新的 RecoverWindow 绑定原作业/目标指纹/持久化预备份,在维护关闭下 执行恢复与逐类校验,通过才恢复服务与入口;失败继续维护。 预备份身份与内容风险在第一笔写入前一起落盘;后台任务必须静默后才停写者; 写入者发布端口即拒绝开窗口;维护占用改为按实例互斥(000072)。
This commit is contained in:
@@ -29,6 +29,16 @@ func (c *exitControl) Inventory(ctx context.Context) ([]Service, error) {
|
||||
return items, nil
|
||||
}
|
||||
|
||||
// idleQuiescer:实例级窗口必须能证明后台任务已空,测试里默认给一个空的。
|
||||
type idleQuiescer struct{ busy bool }
|
||||
|
||||
func (q *idleQuiescer) Idle(context.Context) (bool, string, error) {
|
||||
if q.busy {
|
||||
return false, "asynq pending=1", nil
|
||||
}
|
||||
return true, "asynq=0 pending_ops=0", nil
|
||||
}
|
||||
|
||||
func instanceFixture(t *testing.T) (string, *exitControl, *Coordinator) {
|
||||
t.Helper()
|
||||
root := t.TempDir()
|
||||
@@ -45,6 +55,9 @@ func instanceFixture(t *testing.T) (string, *exitControl, *Coordinator) {
|
||||
if err := engine.SetTarget("instance", "http://127.0.0.1:1/health", nil, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := engine.SetQuiescer(&idleQuiescer{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return root, c, engine
|
||||
}
|
||||
|
||||
@@ -312,32 +325,3 @@ func TestWindowRefusesWhenGateNotDrained(t *testing.T) {
|
||||
t.Fatalf("writers were stopped before the ingress was drained: %v", c.calls)
|
||||
}
|
||||
}
|
||||
|
||||
// 人工恢复后的收尾:服务没起来就必须拒绝(不能靠清记录放行)。
|
||||
func TestFinalizeAfterOperatorRecoveryRequiresHealthyServices(t *testing.T) {
|
||||
_, c, e := instanceFixture(t)
|
||||
_, err := e.RunWindow(context.Background(), "job-manual", func(context.Context) error { return nil },
|
||||
func(ctx context.Context, w *Window) (string, error) {
|
||||
if err := w.MarkContentRisk(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return "", errors.New("内容回滚失败")
|
||||
}, func(error) bool { return false })
|
||||
if err == nil {
|
||||
t.Fatal("blocked window reported success")
|
||||
}
|
||||
// 服务还停着:收尾必须失败。
|
||||
if err := e.FinalizeAfterOperatorRecovery(context.Background(), "job-manual"); err == nil {
|
||||
t.Fatal("finalize accepted a still-stopped target")
|
||||
}
|
||||
for i := range c.services {
|
||||
c.services[i].Running, c.services[i].Healthy = true, true
|
||||
}
|
||||
if err := e.FinalizeAfterOperatorRecovery(context.Background(), "job-manual"); err != nil {
|
||||
t.Fatalf("finalize rejected a recovered target: %v", err)
|
||||
}
|
||||
j, err := e.load("job-manual")
|
||||
if err != nil || j.State != "failed" || j.Code != "operator_recovered" || j.RestoreBlocked {
|
||||
t.Fatalf("journal=%+v err=%v", j, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user