fix(snapshot): 暂停前后强制检查共享源全库任务
build / build (push) Successful in 1m12s

This commit is contained in:
姚章浩
2026-10-28 01:05:44 +08:00
parent 55fba5fc0e
commit bf049cee1f
7 changed files with 103 additions and 8 deletions
@@ -54,6 +54,38 @@ func TestLibraryExportIsolatedPostgres(t *testing.T) {
}
}
}
t.Run("whole source settlement", func(t *testing.T) {
if err := checkLibrarySourceSettlement(ctx, db); err != nil {
t.Fatal(err)
}
for _, tc := range []struct{ name, change, restore string }{
{"other tenant document", `UPDATE knowledges SET parse_status='processing' WHERE id='other-scope'`, `UPDATE knowledges SET parse_status='completed' WHERE id='other-scope'`},
{"other library pending", `INSERT INTO task_pending_ops VALUES(20000,'wiki:ingest','knowledge_base','other-library')`, `DELETE FROM task_pending_ops`},
{"deleted scope pending", `INSERT INTO task_pending_ops VALUES(20000,'wiki:retract','knowledge','physically-deleted-doc')`, `DELETE FROM task_pending_ops`},
{"unknown scope pending", `INSERT INTO task_pending_ops VALUES(20000,'unknown:task','unknown','unknown')`, `DELETE FROM task_pending_ops`},
{"other tenant dead letter", `INSERT INTO task_dead_letters VALUES(20000,'document:process','knowledge_base','other-library')`, `DELETE FROM task_dead_letters`},
} {
t.Run(tc.name, func(t *testing.T) {
if _, err := db.Exec(ctx, tc.change); err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
if _, err := db.Exec(ctx, tc.restore); err != nil {
t.Error(err)
}
})
if _, err := ExportLibrary(ctx, db, scope); err != nil {
t.Fatalf("selected library unexpectedly busy: %v", err)
}
if err := checkLibrarySourceSettlement(ctx, db); err == nil {
t.Fatal("source maintenance allowed while another scope has unfinished work")
}
})
}
if err := checkLibrarySourceSettlement(ctx, db); err != nil {
t.Fatalf("settled source did not recover: %v", err)
}
})
t.Run("MVCC concurrent update", func(t *testing.T) {
wrapper := libraryHookDB{pool: db, hook: func() {
if _, err := db.Exec(ctx, `UPDATE wiki_pages SET content='new-content' WHERE id='wiki-safe'`); err != nil {