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
@@ -15,10 +15,11 @@ import (
)
type captureWriter struct {
running atomic.Bool
db *libraryFixture
late bool
stops int
running atomic.Bool
db *libraryFixture
late bool
lateSource bool
stops int
}
func (c *captureWriter) Inventory(context.Context) ([]libraryfreeze.Service, error) {
@@ -31,14 +32,20 @@ func (c *captureWriter) Stop(context.Context, string) error {
if c.late {
c.db.tx.pending = 1
}
if c.lateSource {
c.db.tx.sourcePending = 1
}
return nil
}
func (c *captureWriter) Start(context.Context, string) error { c.running.Store(true); return nil }
func TestLibraryCaptureMaintenanceOwnsArchiveAndRestoresOnFailure(t *testing.T) {
for _, mode := range []string{"success", "initial-busy", "late-pending", "search-failure"} {
for _, mode := range []string{"success", "initial-busy", "late-pending", "search-failure", "other-library-busy", "other-library-late-pending"} {
t.Run(mode, func(t *testing.T) {
db := newLibraryFixture()
writer := &captureWriter{db: db, late: mode == "late-pending"}
writer := &captureWriter{db: db, late: mode == "late-pending", lateSource: mode == "other-library-late-pending"}
if mode == "other-library-busy" {
db.tx.sourcePending = 1
}
writer.running.Store(true)
if mode == "initial-busy" {
db.tx.pending = 1
@@ -98,7 +105,7 @@ func TestLibraryCaptureMaintenanceOwnsArchiveAndRestoresOnFailure(t *testing.T)
if err == nil {
t.Fatal("invalid candidate succeeded")
}
if mode == "initial-busy" && writer.stops != 0 {
if (mode == "initial-busy" || mode == "other-library-busy") && writer.stops != 0 {
t.Fatal("busy source stopped")
}
return