internal/pkg: abort all pending cures
All checks were successful
Test / Create distribution (push) Successful in 1m4s
Test / Sandbox (push) Successful in 2m48s
Test / Hakurei (push) Successful in 3m48s
Test / ShareFS (push) Successful in 3m53s
Test / Sandbox (race detector) (push) Successful in 5m27s
Test / Hakurei (race detector) (push) Successful in 6m21s
Test / Flake checks (push) Successful in 1m31s

This cancels all current pending cures without closing the cache.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-04-17 22:39:56 +09:00
parent 8d657b6fdf
commit 30a9dfa4b8
2 changed files with 92 additions and 34 deletions

View File

@@ -16,6 +16,7 @@ import (
"path/filepath"
"reflect"
"strconv"
"sync"
"syscall"
"testing"
"unique"
@@ -903,26 +904,46 @@ func TestCache(t *testing.T) {
<-wCureDone
}, pkg.MustDecode("E4vEZKhCcL2gPZ2Tt59FS3lDng-d_2SKa2i5G_RbDfwGn6EemptFaGLPUDiOa94C")},
{"cancel hanging", pkg.CValidateKnown, nil, func(t *testing.T, base *check.Absolute, c *pkg.Cache) {
started := make(chan struct{})
go func() {
<-started
if !c.Cancel(unique.Make(pkg.ID{0xff})) {
panic("missed cancellation")
{"cancel abort block", pkg.CValidateKnown, nil, func(t *testing.T, base *check.Absolute, c *pkg.Cache) {
var wg sync.WaitGroup
defer wg.Wait()
var started sync.WaitGroup
defer started.Wait()
blockCures := func(d byte, n int) {
started.Add(n)
for i := range n {
wg.Go(func() {
if _, _, err := c.Cure(overrideIdent{pkg.ID{d, byte(i)}, &stubArtifact{
kind: pkg.KindTar,
cure: func(t *pkg.TContext) error {
started.Done()
<-t.Unwrap().Done()
return stub.UniqueError(0xbad0 + i)
},
}}); !reflect.DeepEqual(err, stub.UniqueError(0xbad0+i)) {
panic(err)
}
})
}
}()
if _, _, err := c.Cure(overrideIdent{pkg.ID{0xff}, &stubArtifact{
kind: pkg.KindTar,
cure: func(t *pkg.TContext) error {
close(started)
<-t.Unwrap().Done()
return stub.UniqueError(0xbad)
},
}}); !reflect.DeepEqual(err, stub.UniqueError(0xbad)) {
t.Fatalf("Cure: error = %v", err)
started.Wait()
}
blockCures(0xfd, 16)
c.Abort()
wg.Wait()
blockCures(0xff, 1)
if !c.Cancel(unique.Make(pkg.ID{0xff})) {
t.Fatal("missed cancellation")
}
wg.Wait()
for c.Cancel(unique.Make(pkg.ID{0xff})) {
}
c.Close()
c.Abort()
}, pkg.MustDecode("E4vEZKhCcL2gPZ2Tt59FS3lDng-d_2SKa2i5G_RbDfwGn6EemptFaGLPUDiOa94C")},
{"no assume checksum", 0, nil, func(t *testing.T, base *check.Absolute, c *pkg.Cache) {